React.js right way to iterate over object instead of Object.entries
Complete function render in react
const renderbase = ({datalist}) => {
if(datalist){
return Object.keys(datalist).map((item,index) => {
return(
<option value={datalist[item].code} key={index}>
{datalist[item].symbol}
</option>
)
})
}
}
a = {
a: 1,
b: 2,
c: 3
}
Object.keys(a).map(function(keyName, keyIndex) {
// use keyName to get current key's name
// and a[keyName] to get its value
})
A newer version, using destructuring and arrow functions. I'd use this one for new code:
a = {
a: 1,
b: 2,
c: 3
}
Object.entries(a).map(([key, value]) => {
// Pretty straightforward - use key for the key and value for the value.
// Just to clarify: unlike object destructuring, the parameter names don't matter here.
})