Use With Arrays

Lenses are great for arrays too! (2 min. read)

What we just learned applies to arrays as well, but with one change. Instead of lensProp use lensIndex.

Press + to interact
import { lensIndex, view } from 'ramda';
const person = {
firstName: 'Bobo',
lastName: 'Flakes',
friends: [{
firstName: 'Clark',
lastName: 'Kent'
}, {
firstName: 'Bruce',
lastName: 'Wayne'
}, {
firstName: 'Barry',
lastName: 'Allen'
}]
};
const getThirdFriend = lensIndex(2);
const result = view(getThirdFriend, person.friends);
console.log({ result });