.DS_Store
# understand-javascript-arrays
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Plunker</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
// Array.prototype.reduce
const users = [
{
id: '01',
name: 'Shane'
},
{
id: '02',
name: 'Sally'
}
];
const newUsers = users.reduce((obj, user) => {
obj[user.id] = user;
return obj;
}, {});
console.log(newUsers['02'].name) || displayInPreview(newUsers['02'].name);
// display in plunker preview
function displayInPreview(string) {
var newDiv = document.createElement("div");
var newContent = document.createTextNode(string);
newDiv.appendChild(newContent);
document.body.appendChild(newDiv)
}