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' ]
  • 相关阅读:
    easyExcel入门
    UML-从需求到设计--迭代进化
    UML-操作契约总结
    102. Binary Tree Level Order Traversal
    98. Validate Binary Search Tree
    95. Unique Binary Search Trees II
    96. Unique Binary Search Trees
    94. Binary Tree Inorder Traversal
    84. Largest Rectangle in Histogram
    92. Reverse Linked List II
  • 原文地址:https://www.cnblogs.com/youxin/p/2238626.html
Copyright © 2011-2022 走看看