JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

Array.indexOf()

Array.indexOf() ECMAScript 5


search an array

Synopsis

array.indexOf(value) array.indexOf(value, start)

Arguments

value The value to search array for.

Core JavaScript Reference | 727

Array.join()

start

An optional array index at which to begin the search. If omitted, 0 is used.

Returns

The lowest index >= start of array at which the element is === to value, or -1 if no such matching element exists.

Description

This method searches arrayfor an element that is equal to value, and returns the index of the first element it finds. The search begins at the array index specified by start, or at index 0, and continues with successively higher indexes until a match is found or all elements have been checked. The === operator is used to test equality. The return value is the index of the first matching element found, or -1 if no match is found.

Example

['a','b','c'].indexOf('b') // => 1 ['a','b','c'].indexOf('d') // => -1 ['a','b','c'].indexOf('a',1) // => -1

See Also

Array.lastIndexOf() , String.indexOf()

Array.join()

concatenate array elements to form a string

Synopsis

array.join() array.join(separator)

Arguments

separator

An optional character or string used to separate one element of the array from the next in the returned string. If this argument is omitted, a comma is used.

Returns

The string that results from converting each element of array to a string and then concatenating them together, with the separator string between elements.

Description

join() converts each element of an array to a string and then concatenates those strings, inserting the specified separator string between the elements. It returns the resulting string.

You can perform a conversion in the opposite direction—splitting a string into array elements —with the split() method of the String object. See String.split() for details.

Array.length
Example a = new Array(1, 2, 3, "testing"); s = a.join("+"); // s is the string "1+2+3+testing" See Also String.split()
欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/28134.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1