zoukankan      html  css  js  c++  java
  • js Arrays

    Arrays

    Arrays are zero-indexed lists of values. They are a handy way to store a set of related items of the same type (such as strings), though in reality, an array can include multiple types of items, including other arrays.

    Example 2.25: A simple array

    1 var myArray = [ 'hello''world' ];

    Example 2.26: Accessing array items by index

    1 var myArray = [ 'hello''world''foo''bar' ];
    2 console.log(myArray[3]);   // logs 'bar'

    Example 2.27: Testing the size of an array

    1 var myArray = [ 'hello''world' ];
    2 console.log(myArray.length);   // logs 2

    Example 2.28: Changing the value of an array item

    1 var myArray = [ 'hello''world' ];
    2 myArray[1] = 'changed';

    While it's possible to change the value of an array item as shown in “Changing the value of an array item”, it's generally not advised.

    Example 2.29: Adding elements to an array (增加元素到数组)

    1 var myArray = [ 'hello''world' ];
    2 myArray.push('new');

    Example 2.30: Working with arrays

    1 var myArray = [ 'h''e''l''l''o' ];
    2 var myString = myArray.join('');   // 'hello'
     
    3 var mySplit = myString.split('');  // [ 'h', 'e', 'l', 'l', 'o' ]
  • 相关阅读:
    代码面试最常用的10大算法
    ant google compiler 压缩
    美工资源
    面试题
    validate表单验证插件
    laypage分页
    layer弹出框小结
    Thymeleaf
    webApp开发
    grunt自动化构建工具
  • 原文地址:https://www.cnblogs.com/youxin/p/2238626.html
Copyright © 2011-2022 走看看