JSFiddle - React, Tailwind, and code Playground
HTML
<div id="output"></div>
JavaScript
function getUserById(usersArr, userId, cb) {
cb(usersArr.filter(function (el) {
return el.id === userId;
})[0]);
}
var users = [{
id: '15a',
name: 'bob',
email: '[email protected]',
address: '123 main'
}, {
id: 'zxv',
name: 'jim',
email: '[email protected]',
address: '234 main'
}];
getUserById(users, '15a', function (user) {
document.getElementById('output').innerHTML = 'The user with the id 15a has the email of ' + user.email + ' the name of ' + user.name + ' and the address of ' + user.address;
});