Posts

spread operator use in reactjs

We can use spread operator to add two array const result = [...arr1, ...arr2]; We can copy/clone one array/object to other variable const arr3 = [...arr1]; const obj1 = {...obj1}; Extend array value const arr4 = [ 1, 3 , ...arr1]; function myFunction(...theArgs) {  //   } in react we can pass all props using sprad property &lgt

One button click navigate to route path in reactjs

On click of element if we want to navigate route path- import { useHistory } from "react-router-dom";  < button onclick="{handleClick}" type="button">   home </button> const history = useHistory();  function handleClick() {           history.push("/home");  }

How to do sorting array object es6

 To sort objects by its vale  const arr = [   {name:"abc", price: 5},     {name:"pqr", price: 3},    {name:"mno", price: 2}  ]; const result = arr.sort((a,b) => a.price-b.price );

How to merge two array and remove duplicate es6

To merge two array we can use spread operator and remove duplicate const arr1 = ["abc","efg"];  const arr2 = ["efg", "pqr"]; const arr3 = [...array1, ...array2]; const result = [...new Set([arr3)];

How to check any property available in object es6

 To check whether property available in object const result = myObj.hasOwnProperty('id');

How to count length of object keys es6

To check the length of object (obj) keys const result = Object.keys(obj).length

How to filter one array from other array es6

const filtered = arr1.filter( (e) =>  !arr2.includes(e.key));