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()
shift()
100% like push and pop, only on the begining
unshift(): add to head.
Splice: delete some elements:
.fill() fill all indexes.
Array.prototype.join()
concat and return a new String
join(" + ") use " + " to concat
Array.prototype.slice()
get some return a new array
Array.prototype.lastIndexOf()
return the last index..
Traverse:
let finalVal = oldArray.reduce((accumulator, currentValue, currentIndex, array) => { ... }), initalValue;
Array.prototype.some()
as least one or return false;
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
Object.assign()
Copies the values of all enumerable own properties from one or more source objects to a target object.
Object.keys()
Returns an array containing the names of all of the given object's own enumerable string properties.
Object.values()
Returns an array containing the values that correspond to all of a given object's own enumerable string properties.
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:
string.charAt()
String.prototype.constructor
Specifies the function that creates an object's prototype.String.prototype.length
Reflects the length of the string.
String.prototype.concat()
Combines the text of two strings and returns a new string.
String.prototype.concat()
Combines the text of two strings and returns a new string.String.prototype.includes()
Determines whether one string may be found within another string.
String.prototype.includes()
Determines whether one string may be found within another string.String.prototype.indexOf()
Returns the index within the calling String
object of the first occurrence of the specified value, or -1 if not found.
String.prototype.lastIndexOf()
Returns the index within the calling String
object of the last occurrence of the specified value, or -1 if not found.
String.prototype.match()
Used to match a regular expression against a string.String.prototype.matchAll()
Returns an iterator of all matches.String.prototype.normalize()
Returns the Unicode Normalization Form of the calling string value.
String.prototype.repeat()
Returns a string consisting of the elements of the object repeated the given times.
String.prototype.replace()
Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.
String.prototype.replace()
Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.String.prototype.search()
Executes the search for a match between a regular expression and a specified string.
String.prototype.slice()
Extracts a section of a string and returns a new string.
String.prototype.slice()
Extracts a section of a string and returns a new string.String.prototype.split()
Splits a String
object into an array of strings by separating the string into substrings.
String.prototype.split()
Splits a String
object into an array of strings by separating the string into substrings.String.prototype.substring()
Returns the characters in a string between two indexes into the string.
String.prototype.substring()
Returns the characters in a string between two indexes into the string.String.prototype.toLowerCase()
Returns the calling string value converted to lower case.
String.prototype.toUpperCase()
Returns the calling string value converted to uppercase.
str.split("dog").join("cat");
String.prototype.toString()
Returns a string representing the specified object. Overrides the Object.prototype.toString()
method.
String.prototype.toString()
Returns a string representing the specified object. Overrides the Object.prototype.toString()
method.MethodsSection
String.fromCharCode()
Returns a string created by using the specified sequence of Unicode values.String.fromCodePoint()
Returns a string created by using the specified sequence of code points.String.raw()
Returns a string created from a raw template string.
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?