I have object like the one below and every time i call object["key"] it return undefined for some reason
i tried the following and still getting undefined
object.keyName
object[keyName]
object["keyName"]
all of them return undefined
let sam = {
"facebook": "https://facebook.com",
"instagram": "https://Instagram.com",
"placeName": "dazzlement",
"snapchat": "https://snapchat.com",
"twitter": "https://twitter.com",
}
let's say i want placeName value i tried
sam.placeName
sam[placeName]
sam["placeName"]
all of them return undefined.
-------- UPDATE ----------
i'm using react native with Parse JS SDK here is the code for getting values from Parse Database and send it as props to a component where it will display the results as card
this.state = {
items: null,
loaded: false
};
componentDidMount() {
this.queryValues()
}
queryValues = async id => {
let cy = this;
const GameScore = Parse.Object.extend('social');
const query = new Parse.Query(GameScore);
query.equalTo('A', 1);
query.equalTo('B', 2);
const results = await query.find().then(
results => {
cy.setState({
items: results
loaded: true,
})
},
error => {}
);
};
render() {
return (
{
this.state.loaded ?
<FlatList
data = {this.state.items}
renderItem = {
({item}) => <SocialCard social={item} /> } /
>
: <
Text> Loading </Text>
}
);
}
}
In the component here is the code
render() {
const {
social
} = this.props;
console.log(social)
return (
<Text>{this.props.}</Text>
);
}
the log show up like this
Object {
"facebook": "https://facebook.com",
"instagram": "https://Instagram.com",
"placeName": "dazzlement",
"snapchat": "https://snapchat.com",
"twitter": "https://twitter.com",
}
this should return all links
let sam = {
facebook: 'facebook.com', // you don't need " " for facebook
instagram: 'instagram.com'
}
for (let i in sam){
console.log(sam[i])
}
sam.facebook // facebook.com
sam.instagram // instagram.com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.