Skip to content

Instantly share code, notes, and snippets.

@simonjcarr
Last active October 29, 2020 14:32
Show Gist options
  • Save simonjcarr/f15147f9ef14bd850ff3ecff2bb1f8e6 to your computer and use it in GitHub Desktop.
Save simonjcarr/f15147f9ef14bd850ff3ecff2bb1f8e6 to your computer and use it in GitHub Desktop.
findFilterArrayData
[
{
"id": 1,
"name": "Joe Bloggs"
},
{
"id": 2,
"name": "Jane Doe"
},
{
"id": 3,
"name": "John Doe",
"address": {
"street": "21 Lime Street",
"city": "London"
}
}
]
let users = require('./data.json');
let filterDoe = users.filter(user => user.name.includes("Doe"))
console.log(filterDoe)
let users = require('./data.json');
let findCityLondon = users.find((user) => {
try {
return user.address.city.includes('London');
} catch {
return false
}
});
console.log(findCityLondon);
let users = require('./data.json');
let findCityLondon = users.find(user => {
return user.address.city.includes("London")
})
console.log(findCityLondon)
let users = require('./data.json');
let findDoeUsers = users.find((user) => user.name.includes('Doe'));
console.log(findDoeUsers);
let users = require('./data.json');
let findId1user = users.find(user => user.id == 1)
console.log(findId1user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment