Workspace
  • Study Book
  • WEB Network HTTP etc
    • Performance Optimization
    • Performance Optimization
    • HTTP/2 & SPDY
    • WebSocket
    • HTTP Header
    • Cross-Origin Resource Sharing
    • JSON, XML, other format
  • Javascript
    • Promise
    • make API call
    • Web API
    • Common JS
    • AJAX
    • Event DOM and delegation
    • ES6 new features
    • special function
    • function API
  • React
    • class component
    • Example
    • Lifting functions/ state up
    • Hot Loader
    • Testing
    • New Features
    • Hook
    • Simple code
    • Life Cycle
  • CSS
    • Horizontal & Vertical Align
    • GPU Animation
    • transform-function
    • LVHA Pseudo-classes
    • Selector
    • How To CSS
  • HTML
  • Redux
  • NodeJS
    • File System
  • express
    • express questions
    • express mongodb
  • Restful API
  • MongoDB
  • Compare
  • Test
    • Jest
  • Deploy development
  • coding question
  • DevOps
  • Webpack
  • GraphQL
Powered by GitBook
On this page
  • Array
  • Object
  • Reduce()
  • For Loop:
  • String
  • String instance
  • 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.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.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.substring()Returns the characters in a string between two indexes into the string.
  • String.prototype.toString()Returns a string representing the specified object. Overrides the Object.prototype.toString() method.
  • MethodsSection
  • typeof
  • JSON

Was this helpful?

  1. Javascript

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);

array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

Matching: indexOf(), lastIndexOf(), find(), findIndex(), some(), every(), join()ty

Empty the Array

var arr = [1]

  1. arr.splice(0, arr.length);

  2. arr.length = 0;

  3. arr = []

traverse forEach executes the provided callback once for each element present in the array in ascending order.

fruits.forEach(function (item, index, array) {
    console.log(item, index);
});

•Does not make a copy of the array before iterating.

split
var myArray = myData.split(',');
var myNewString = myArray.join(',');
myNewString;

push(): add to last.

pop(): delete last and return this one.

toString()

  1. var dogNames = ["Rocket","Flash","Bella","Slugger"];
    dogNames.toString(); //Rocket,Flash,Bella,Slugger

var myArray = ['Manchester', 'Leeds', 'Carlisle'];
myArray.push('Cardiff');
myArray.pop();
pop() delete last one
var removedItem = myArray.pop();

unshift() shift() 100% like push and pop, only on the begining

unshift(): add to head.

myArray.unshift('Edinburgh');
var removedItem = myArray.shift();

.indexOf(element) return the index

Splice: delete some elements:

array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
start position, delete number, items to add.from start
return the [] that deleted.
var removedItem = fruits.splice(pos, 1); 

.fill() fill all indexes.

.concat()

Array.prototype.includes()

Array.prototype.join() concat and return a new String

join(" + ") use " + " to concat

Array.prototype.slice() get some return a new array

arr.slice(begin, end);
// [begin, end)

Array.prototype.toString()

Array.prototype.lastIndexOf() return the last index..

Traverse:

Array.prototype.forEach()

Array.prototype.map()

Array.prototype.reduce()

let finalVal = oldArray.reduce((accumulator, currentValue, currentIndex, array) => { ... }), initalValue;

Array.prototype.some() as least one or return false;

Array.prototype.filter()

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) => { })

arr.reduce(callback(accumulator, currentValue[, index[, array]])[, initialValue])

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(thing)
new String(thing)

Character access

string.charAt()

return 'cat'[1];

String instance

String.prototype.constructorSpecifies the function that creates an object's prototype.String.prototype.lengthReflects the length of the 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.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.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.

str.slice(beginIndex[, endIndex])

String.prototype.split()Splits a String object into an array of strings by separating the string into substrings.

str.split([separator[, limit]])

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.

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

var str = new String('String');
var num = new Number(100);
typeof str; // It will return 'object'
typeof num; // It will return 'object'

Float

parseFloat(String s) return float

JSON

JSON.stringify() Convert a JavaScript object into a string

JSON.parse() Convert text into a JavaScript object:

Previousspecial functionNextReact

Last updated 4 years ago

Was this helpful?