Strict equality

Strict equality is used when you're looking for a value in a collection, and you have something with which you can compare it. For example, you could define a filter function that uses strict equality to look for values that equal 1 or 2, as follows:

const filter = i => i === 1 || i === 2;

You can then pass this function to the filter() method of a list:

const myList = List.of(1, 2, 3);
const myFilteredList = myList.filter(filter);

console.log('myList', myList.toJS());
// -> myList [ 1, 2, 3 ]
console.log('myFilteredList', myFilteredList.toJS());
// -> myFilteredList [ 1, 2 ]

You can use the same function to filter maps, as shown here:

const myMap = Map.of(
'one', 1,
'two', 2,
'three', 3
);
const myFilteredMap = myMap.filter(filter);

console.log('myMap', myMap.toJS());
// -> myMap { one: 1, two: 2, three: 3 }
console.log('myFilteredMap', myFilteredMap.toJS());
// -> myFilteredMap { one: 1, two: 2 }
Note how the result of filtering a map is another map. This is difficult to do with plain JavaScript objects, even with the help of a library. With Immutable.js, you'll always get a map as the result.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.76