js array of common methods
js array common methods are as follows:
(1) unshift () in the longitudinal front to add the contents of the array, the return value is an array
The first element (2) shift () to delete the array, the return value to remove elements
(3) push () to add elements to the end of the array, the array is returned chang
(4) () to delete the last element of the array of pop, returns the value of the element removed
(5) concat () to connect the two arrays
(6) reverse () The contents of the array in reverse order
(7) splice (start, num, val1, val2, val3, ...) from start to start, num delete entries and add val1, val2, val3 ... the return item is deleted
(8) slice (start, end) beginning at start key, the end of the first End + 1, returns the value of a new array of items start to end-1
(9) sort () sorts the elements of the array (but not as a whole a discharge as !!: 23,3; 23 in front 3)
(10) .isArray () determines whether the array, the return value boolean
(11) .toString () into a string
(12) .join () the elements of the array into a string, the element is divided by the specified delimiter, the default is a comma
Specific examples are as follows: We unified with var let = arr [1,2,3,4,5]
(1)arr.unshift(6,7) console.log(arr) //[6,7,1,2,3,4,5] 7
(2)arr.shift() console.log(arr) //[2,3,4,5] 1
(3)arr.push(6) console.log(arr) //[1,2,3,4,5,6] 6
(4)arr.pop() console.log(arr) //[1,2,3,4] 5
(5)var arr1=[11,22] arr.concat(arr1) console.log(arr) //[1,2,3,4,5,11,22]
(6)arr.reverse() console.log(arr) //[5,4,3,2,1]
(7)arr.splice(2,1,33) console.log(arr) //[1,2,33,4,5]
(8)arr.slice(2,4) console.log(arr) //[3,4]
(9)arr.sort() console.log(arr) //[1,2,3,4,5]
(10)arr.isArray() //true
(11)arr.toString() console.log(arr) //1,2,3,4,5
(12)arr.join('.') console.log(arr) //1.2.3.4.5
js array iteration:
(1) .map () map of the maps means; is each of the array elements and processing operation, return the new array, the array unchanged original
was arr = [1,2,3,4,5]
let newArr=arr.map((item)=>{
return item*2
})
console.log (newArr) [1,2,3,4,5] // original array
console.log (newArr) [2,4,6,8,10] // new array
(2) .forEach () array where each element provided by the function performed, no return value, directly modify the original array
was arr = [1,2,3,4,5]
let newArr=arr.forEach((item)=>{
return item*2
})
console.log (arr) [1,2,3,4,5] // original array
console.log (newArr) undefined // new array
(3) .reduce () reduce meaning as is to reduce the elements of an array is by some operation comes down to a value
js array common methods are as follows:
(1) unshift () in the longitudinal front to add the contents of the array, the return value is an array
The first element (2) shift () to delete the array, the return value to remove elements
(3) push () to add elements to the end of the array, the array is returned chang
(4) () to delete the last element of the array of pop, returns the value of the element removed
(5) concat () to connect the two arrays
(6) reverse () The contents of the array in reverse order
(7) splice (start, num, val1, val2, val3, ...) from start to start, num delete entries and add val1, val2, val3 ... the return item is deleted
(8) slice (start, end) beginning at start key, the end of the first End + 1, returns the value of a new array of items start to end-1
(9) sort () sorts the elements of the array (but not as a whole a discharge as !!: 23,3; 23 in front 3)
(10) .isArray () determines whether the array, the return value boolean
(11) .toString () into a string
(12) .join () the elements of the array into a string, the element is divided by the specified delimiter, the default is a comma
Specific examples are as follows: We unified with var let = arr [1,2,3,4,5]
(1)arr.unshift(6,7) console.log(arr) //[6,7,1,2,3,4,5] 7
(2)arr.shift() console.log(arr) //[2,3,4,5] 1
(3)arr.push(6) console.log(arr) //[1,2,3,4,5,6] 6
(4)arr.pop() console.log(arr) //[1,2,3,4] 5
(5)var arr1=[11,22] arr.concat(arr1) console.log(arr) //[1,2,3,4,5,11,22]
(6)arr.reverse() console.log(arr) //[5,4,3,2,1]
(7)arr.splice(2,1,33) console.log(arr) //[1,2,33,4,5]
(8)arr.slice(2,4) console.log(arr) //[3,4]
(9)arr.sort() console.log(arr) //[1,2,3,4,5]
(10)arr.isArray() //true
(11)arr.toString() console.log(arr) //1,2,3,4,5
(12)arr.join('.') console.log(arr) //1.2.3.4.5
js array iteration:
(1) .map () map of the maps means; is each of the array elements and processing operation, return the new array, the array unchanged original
was arr = [1,2,3,4,5]
let newArr=arr.map((item)=>{
return item*2
})
console.log (newArr) [1,2,3,4,5] // original array
console.log (newArr) [2,4,6,8,10] // new array
(2) .forEach () array where each element provided by the function performed, no return value, directly modify the original array
was arr = [1,2,3,4,5]
let newArr=arr.forEach((item)=>{
return item*2
})
console.log (arr) [1,2,3,4,5] // original array
console.log (newArr) undefined // new array
(3) .reduce () reduce meaning as is to reduce the elements of an array is by some operation comes down to a value