javascript - I want to pull the names with the top 5 values out of an object...in React -
i have state set empty object. when searched returns list of names values inside of object. how pull names top 5 values names render?
here initial state:
export default class app extends react.component { constructor() { super(); this.state = { searchinput: '', selectedartist: {}, selectalbums: {}, artistcounts: {}, };
here fucntion gets names , gives them value:
gettrackdetails(track) { request.get(`api`) .then((track) => { const { artists } = track.body; const artistcounts = this.state.artistcounts; (let = 0; < artists.length; i++) { const artist = artists[i]; const artistname = artist.name; if (artistcounts[artistname]) { artistcounts[artistname] += 1; } else { artistcounts[artistname] = 1; } }
not sure getting right looks need limit
for (let = 0; < artists.length; i++) {
to run 5 times so:
var maxlength = artists.length >= 5 ? 5 : artists.length; (let = 0; < maxlength ; i++) {
Comments
Post a Comment