Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

creating array of objects usinng reduce js

const posts = [
    {id: 1, category: "frontend", title: "All About That Sass"},
    {id: 2, category: "backend", title: "Beam me up, Scotty: Apache Beam tips"},
    {id: 3, category: "frontend", title: "Sanitizing HTML: Going antibactirial on XSS attacks"}
];

const categoryPosts = posts.reduce((acc, post) => {
    let {id, category} = post;
    return {...acc, [category]: [...(acc[category] || []), id]};
}, {});
Comment

PREVIOUS NEXT
Code Example
Javascript :: import js file into another 
Javascript :: importing json file in javascript 
Javascript :: onclick toggle class react 
Javascript :: chalk nodeks 
Javascript :: check local storage javascript 
Javascript :: how to get which key is pressed in javascript 
Javascript :: settimeout in javascript 
Javascript :: js sleep 
Javascript :: res.json in express 
Javascript :: check if string contains lowercase javascript 
Javascript :: add new element useState array 
Javascript :: javascript download current html page 
Javascript :: javascript break out of loop 
Javascript :: Get LocalStorage from WebView react native 
Javascript :: app.post (req res) get data 
Javascript :: javascript blob to file 
Javascript :: how to change color on js 
Javascript :: get format file in javascript 
Javascript :: copy one array to another javascript 
Javascript :: print json shopify 
Javascript :: count value a to b character javascript 
Javascript :: location of release apk in react native 
Javascript :: number round 
Javascript :: sum all the values in an array javascript 
Javascript :: js map array to dictionary 
Javascript :: renemane object key js 
Javascript :: change next js default port 
Javascript :: reactjs install 
Javascript :: checkbox set checked jquery 
Javascript :: what is synchronous and asynchronous in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =