How to find max and min value in array

let intArray = [600,6,500,1];
let min=0;
let max=0;
intArray.forEach((data)=>{
 
  if(data > max) {
    max=data;
    min=data;
  }else if(data < min) {
    min = data
  }
 
})

console.log(min);
console.log(max);

How to get the value of state after using setState in React

this.setState({ name: "Hello Chris1993!" }, () => {
  console.log(this.state.name); // output: Hello Chris1993!
});


For Functional Component Use useEffect.

useEffect(() => {
  console.log(state) // do something after state has updated 
}, [state]) 

Get difference between 2 dates in JavaScript

const date1 = new Date('10/15/2020');
const date2 = new Date('12/1/2020');

const diffTime = Math.abs(date2 - date1); // time in milliseconds
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); // convert time to days

Note: Difference in date always return in milliseconds.

How to remember

- 1000 Milliseconds to 1 Sec
- 60 Sec 1 Minute
- 60 Min 1Hr
- 24 Hr to 1 Day