function API
Array, String, Object
Array
InPlace:push()/pop(), shift()/unshift(), splice(), copyWithin(), fill(), reverse(), sort()
ReturnNew: concat(), slice()
***
splice(), splice(startIndex, deleteNumber, input new to here);
Matching: indexOf(), lastIndexOf(), find(), findIndex(), some(), every(), join()ty
Empty the Array
var arr = [1]
arr.splice(0, arr.length);
arr.length = 0;
arr = []
traverse forEach executes the provided callback once for each element present in the array in ascending order.
•Does not make a copy of the array before iterating.
push(): add to last.
pop(): delete last and return this one.
unshift(): add to head.
Splice: delete some elements:
.fill() fill all indexes.
join(" + ") use " + " to concat
Traverse:
let finalVal = oldArray.reduce((accumulator, currentValue, currentIndex, array) => { ... }), initalValue;
Object
•map transforms the elements in the array
•Based on a function you give
•Return a copy and doesn’t modify the input array
•When the function you provide gets called, it gets called for each element with three arguments: the element itself, the index of the element, and the array itself (which is seldom useful).
•filter removes unwanted things from an input array.
•Based on a function you give
•Return a copy and doesn’t modify the input array
•map and filter often are used together
Reduce()
array.reduce((accumulator, currentValue, currentIndex, sourceArray) => { })
For Loop:
for(x of Array) {// } arrays strings maps nodelists etc
but loop an object: we use in.
for (x in Object){ // }
While loop / do while loop
String
Strings can also be created using the String
global object directly:
str.split("dog").join("cat");
typeof
typeof null = objec
Type
result
Null
"object"
(见下文)
Boolean
"boolean"
Number
"number"
String
"string"
Symbol (ECMAScript 6 新增)
"symbol"
宿主对象(由JS环境提供)
Implementation-dependent
函数对象([[Call]] 在ECMA-262条款中实现了)
"function"
任何其他对象
"object"
New
Float
parseFloat(String s) return float
JSON
JSON.stringify() Convert a JavaScript object into a string
JSON.parse() Convert text into a JavaScript object:
Last updated
Was this helpful?