0👍
You could use loash’s find method to do this e.g.
Documentation: https://lodash.com/docs/4.17.11#find
_.find(authors, { 'id': 1 });
- [Vuejs]-Hide popup box when clicked anywhere on the document
- [Vuejs]-How does one configure azure web apps to display custom error pages?
0👍
I’d use the native Array.filter method, like so:
let tolkien = authors.filter(author => !!author.id === 1)
Using .filter means you don’t need to include a library like lodash just for this one method.
0👍
You can create a new object with keys mapped to authors (i.e author[1] = {id: 1, ...}
) which will let you quickly and easily access any author by his/her id. Example:
let authorByIds = {};
authors.forEach(author => {
authorByIds[author.id] = {...author};
});
let firstBook = books[0];
console.log(authorByIds[firstBook.author]);
// will output author with id = 1, i.e J.R.R. Tolkien
- [Vuejs]-Function assigned to Vue.prototype returns unresolved Promise
- [Vuejs]-Input data got reset after checkbox is checked when using Vue js
Source:stackexchange.com