How to know the user's name with javascript
[
{
id: 3843558,
cid: 4070139,
text: ' Hi today',
user: 'Eklavya',
rto: [ [Object], [Object], [Object], [Object] ],
time: 1616050866
}
]
How to know the user's name with javascript
[
{
id: 3843558,
cid: 4070139,
text: ' Hi today',
user: 'Eklavya',
rto: [ [Object], [Object], [Object], [Object] ],
time: 1616050866
}
]
If the variable is called users then in this case users[0].user or users[0]['user']. users = JSON.parse(str) if you have string str. fs = require('fs'); fs.readFile(file, [encoding], [callback]); if you need to read the string from file (nodejs).
const arr = [
{
id: 3843558,
cid: 4070139,
text: ' Hi today',
user: 'Eklavya',
rto: [ [Object], [Object], [Object], [Object] ],
time: 1616050866
}
]
//If multiple object exist..
const users = arr.map(obj=>{
return obj.user
})
//For single object
let name = arr[0].user
//OR
let name = (arr[0])['user']