A blog dedicated to creative design, web design tips and tutorials ..
xtrasoft web template
Get link
Facebook
X
Pinterest
Email
Other Apps
-
xtrasoft a fixed width layout design This template is designed using Photoshop. With a High Quality finish this eye catching design. I hope you are enjoying the layout and designs.
How to Remove Array Duplicates in ES6 Below is the sample array we have, class7 comes two times. var arr = ["class5","class7","class2","class7"]; we want to remove the duplicates value var result = [...new Set(arr)]; // result = ["class5","classs7","class2"] Now lets assume we have array object and we need to remove objects which has duplicate id var arr = [ {id: 1, name: "test"}, {id: 2, name: "test2"}, {id: 1, name: "test3"}, {id: 3, name: "test4"} ] var result = [...new Set(arr.map(({id}) => id))].map((val) => arr.find(({id}) => id === val));
How to check if value id null or undefined. simple way is just check if has value! Like if(value) { // ... } will return true if value is not: null, undefined, NaN, empty string (""), 0, false It’s fulfill our requirements but also check additional conditions Like we want to check id is null or undefined but in response we got id = 0 In this condition it will fail because we just need to check null or undefined if(value !== undefined || value !== null){ // ... }
How to check the existence of a key in JavaScript Object const myObj = { a: 1, b: 2}; We need to check whether I’d exist in object or not! const result = myObj.hasOwnProperty('id'); // false Or const result = 'id' in myObj; // false Or const result = myObj.id !== undefined; // false
Comments