const usersA = [
{userId: '1', name: 'hyerin'},
{userId: '2', name: 'Neo'}
]
const usersB = [
{userId: '1', name: 'hyerin'},
{userId: '3', name: 'Amy'}
]
const usersC = usersA.concat(usersB)
console.log('concat', usersC) //concat (4) [{…}, {…}, {…}, {…}]
/* 0: {userId: "1", name: "hyerin"}
1: {userId: "2", name: "Neo"}
2: {userId: "1", name: "hyerin"}
3: {userId: "3", name: "Amy"} */
const usersA = [
{userId: '1', name: 'hyerin'},
{userId: '2', name: 'Neo'}
]
const usersB = [
{userId: '1', name: 'hyerin'},
{userId: '3', name: 'Amy'}
]
const usersC = usersA.concat(usersB)
console.log('concat', usersC) //concat (4) [{…}, {…}, {…}, {…}]
/* 0: {userId: "1", name: "hyerin"}
1: {userId: "2", name: "Neo"}
2: {userId: "1", name: "hyerin"}
3: {userId: "3", name: "Amy"} */
console.log('uniqBy',_.uniqBy(usersC, 'userId')) //uniqBy (3) [{…}, {…}, {…}]
/* 0: {userId: "1", name: "hyerin"}
1: {userId: "2", name: "Neo"}
2: {userId: "3", name: "Amy"} */
const usersA = [
{userId: '1', name: 'hyerin'},
{userId: '2', name: 'Neo'}
]
const usersB = [
{userId: '1', name: 'hyerin'},
{userId: '3', name: 'Amy'}
]
const usersD = _.unionBy(usersA, usersB, 'userId')
console.log('unionBy', usersD) //unionBy (3) [{…}, {…}, {…}]
/* 0: {userId: "1", name: "hyerin"}
1: {userId: "2", name: "Neo"}
2: {userId: "3", name: "Amy"} */
const users = [
{ userId: '1', name: 'hyerin' },
{ userId: '2', name: 'Neo' },
{ userId: '3', name: 'Amy' },
{ userId: '4', name: 'Evan' },
{ userId: '5', name: 'Lewis' }
]
const foundUser = _.find(users, { name: 'Amy' })
console.log(foundUser) //{userId: "3", name: "Amy"}
const users = [
{ userId: '1', name: 'hyerin' },
{ userId: '2', name: 'Neo' },
{ userId: '3', name: 'Amy' },
{ userId: '4', name: 'Evan' },
{ userId: '5', name: 'Lewis' }
]
const foundUserIndex = _.findIndex(users, { name: 'Amy' })
console.log(foundUserIndex) //2
const users = [
{ userId: '1', name: 'hyerin' },
{ userId: '2', name: 'Neo' },
{ userId: '3', name: 'Amy' },
{ userId: '4', name: 'Evan' },
{ userId: '5', name: 'Lewis' }
]
_.remove(users, { name: 'hyerin' })
console.log(users) //(4) [{…}, {…}, {…}, {…}]
/* 0: {userId: "2", name: "Neo"}
1: {userId: "3", name: "Amy"}
2: {userId: "4", name: "Evan"}
3: {userId: "5", name: "Lewis"} */