Last active
September 8, 2020 17:56
-
-
Save pajaydev/cb421a6285df7ad727baa52c0e402e5e to your computer and use it in GitHub Desktop.
JS Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use reduce function to find sum of all elements in array | |
const array = [1,2,3,4,5]; | |
const sumValue = array.reduce((sum, value)=> sum + value, 0); // 15 | |
// check all the children is valid or not. | |
root.children.every(child => !child) | |
// filtering the values in JSON.stringify. | |
const person = { | |
name: "Ajaykumar", | |
company: "eBay" | |
} | |
const output = JSON.stringify(person, (key,value) => { | |
if(key === "company") return undefined; | |
return value; | |
}); | |
console.log(output) // {"name":"Ajaykumar"} | |
// check if its mac browser | |
const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment