Here is the full list of mostly used JavaScript inbuilt functions along with their definitions and usage examples, categorized for easy reading.
✅ ARRAYS
constarr=[1,2,3];// 1. push() – Adds element to the endarr.push(4);// [1,2,3,4]// 2. pop() – Removes last elementarr.pop();// [1,2,3]// 3. shift() – Removes first elementarr.shift();// [2,3]// 4. unshift() – Adds element at the startarr.unshift(1);// [1,2,3]// 5. concat() – Merges arraysarr.concat([4,5]);// [1,2,3,4,5]// 6. slice() – Extracts a section (non-destructive)arr.slice(0,2);// [1,2]// 7. splice() – Adds/removes items (destructive)arr.splice(1,1);// removes 1 element at index 1// 8. indexOf() – Finds index of an elementarr.indexOf(3);// returns index or -1// 9. filter() – Filters based on a conditionarr.filter(x=>x>1);// 10. map() – Transforms each elementarr.map(x=>x*2);// 11. Array.from() – Converts iterable/string to arrayArray.from('abc');// ['a','b','c']// 12. toString() – Converts array to comma stringarr.toString();// "1,3"// 13. includes() – Checks for existencearr.includes(3);// true// 14. sort() – Sorts arrayarr.sort();// in-place sort// 15. reverse() – Reverses arrayarr.reverse();// 16. join() – Joins into a stringarr.join('-');// "1-3"// 17. find() – Finds first matching elementarr.find(x=>x>1);// 18. forEach() – Loops through elementsarr.forEach(x=>console.log(x));// 19. every() – Checks if all elements meet conditionarr.every(x=>x>0);// 20. some() – Checks if any meet conditionarr.some(x=>x===3);
✅ STRINGS
letstr="hello";// 1. charAt() – Gets character by indexstr.charAt(1);// 'e'// 2. toUpperCase() – Uppercasestr.toUpperCase();// 3. toLowerCase() – Lowercasestr.toLowerCase();// 4. indexOf() – First occurrence indexstr.indexOf('l');// 5. lastIndexOf() – Last occurrence indexstr.lastIndexOf('l');// 6. substring() – Slice string between indexesstr.substring(1,4);// 7. replace() – Replace part of stringstr.replace('e','a');// 8. split() – Split into arraystr.split('');// ['h','e','l','l','o']// 9. trim() – Removes whitespace" hello ".trim();// "hello"
✅ OBJECTS
constobj={a:1,b:2};// 1. Object.keys() – Array of keysObject.keys(obj);// 2. Object.values() – Array of valuesObject.values(obj);// 3. Object.entries() – Array of [key, value]Object.entries(obj);// 4. Object.assign() – Merge objectsObject.assign({},obj);// 5. Object.freeze() – Lock object (no change)Object.freeze(obj);// 6. Object.seal() – Prevent add/deleteObject.seal(obj);// 7. hasOwnProperty() – Check own propertyobj.hasOwnProperty('a');// 8. Object.create() – Create with prototypeconstnewObj=Object.create(obj);
✅ DATE
constdate=newDate();// 1. new Date() – Current date/time// 2. getDate() – Day of the monthdate.getDate();// 3. getMonth() – Month (0-11)date.getMonth();// 4. getFullYear() – Yeardate.getFullYear();// 5. getHours(), getMinutes(), getSeconds()date.getHours();date.getMinutes();date.getSeconds();// 6. toISOString() – ISO stringdate.toISOString();// 7. toLocaleDateString() – Localized datedate.toLocaleDateString();// 8. getTime() – ms since 1970date.getTime();
After my first contact with a computer in the 1980's, I taught myself to program in BASIC and Z80 assembler. I went on to study Computer Science and have enjoyed a long career in Software Engineering.
Top comments (1)
My apologies but I am not sure what this post is intended to offer. Readers might be better off reading an authoritative source such as MDN