befors refresh how to get local storage value code example

Example 1: jq storage object on refresh

if(!localStorage.getItem('initData') || JSON.parse(localStorage.getItem('initData')).length === 0){
    $window.localStorage.setItem('initData', JSON.stringify($scope.initData));
}

Example 2: index localstorage object

const data = [
  {id: 'jijijoj',rating: 'g'}, 
  {id: 'iojiojoi',rating: 'r'}, 
  {id: 'eawfe',rating: 'pg'}, 
  {id: 'ewfewfwe',rating: 'g'}, 
  {id: 'ewfewfew',rating: 'r'}
];

// get index of element with id `iojiojoi`
const index = data.findIndex(item => item.id === 'iojiojoi');

console.log(index);