reference: https://www.toptal.com/javascript/interview-questions
-
var fruits = ["Banana", "Orange", "Apple", "Mango"]; var a = fruits.indexOf("Apple")
-
'aeiou'.includes('i')
-
var objclone = Object.assign({},obj);
-
var myArray = ['a', 'b', 'c', 'd']; myArray.push('end'); myArray.unshift('start'); console.log(myArray); // ["start", "a", "b", "c", "d", "end"] With ES6, one can use the spread operator:
myArray = ['start', ...myArray]; myArray = [...myArray, 'end'];
-
Array.from(Array(b).keys(),(e)=> e+1); // create array from 1 t0 b
-
Arr.reduce((a,b)=>(a+b),0); // get the sum of array
-
number.toString(10) // change number to string
-
s.substring(0,s.length-2) s.slice() // slice string
-
'#'.repeat(i+1).padStart(n)
-
string repeat padstart slice substring split
-
array: forEach reverse reduce Array.from() indexOf keys
-
set: has size
-
map: size forEach has set get keys values