Add new properties to object in javascript not work proper?
up vote
-1
down vote
favorite
Hi I'm getting stuck with one problem that seem so easy :
I want to add new properties to an existing object, but it's not work proper
here my code :
challengeSearchNearBy: async function (longitude , latitude,min_distance,max_distance) {
var challengeNearBy = await Challenge.find({
location: {
$near: {
$geometry: { type: "Point", coordinates: [longitude, latitude] },
$minDistance: min_distance,
$maxDistance: max_distance
}
}
});//limit(30);
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
o.challenger_club_name = challenger_club.club_name;
o.challenger_club_avatar = challenger_club.avatar;
o.conqueror_club_name = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name;
o.conqueror_club_avatar = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
console.log(o.challenger_club_name); // this line logged what I want (challenger_club_name)
return o; // but this object not contain what I want (challenger_club_name, challenger_club_avatar ...)
});
const challenges = await Promise.all(challengesPromise);
return challenges;
},
javascript json object properties
add a comment |
up vote
-1
down vote
favorite
Hi I'm getting stuck with one problem that seem so easy :
I want to add new properties to an existing object, but it's not work proper
here my code :
challengeSearchNearBy: async function (longitude , latitude,min_distance,max_distance) {
var challengeNearBy = await Challenge.find({
location: {
$near: {
$geometry: { type: "Point", coordinates: [longitude, latitude] },
$minDistance: min_distance,
$maxDistance: max_distance
}
}
});//limit(30);
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
o.challenger_club_name = challenger_club.club_name;
o.challenger_club_avatar = challenger_club.avatar;
o.conqueror_club_name = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name;
o.conqueror_club_avatar = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
console.log(o.challenger_club_name); // this line logged what I want (challenger_club_name)
return o; // but this object not contain what I want (challenger_club_name, challenger_club_avatar ...)
});
const challenges = await Promise.all(challengesPromise);
return challenges;
},
javascript json object properties
If all you want iso.challenger_club_name
, thenreturn o.challenger_club_name
?
– CertainPerformance
Nov 11 at 3:09
@CertainPerformance I want object o within new properties such as : challenger_club_name, challenger_club_avatar ...
– every Bit
Nov 11 at 3:12
What does it contain instead?
– CertainPerformance
Nov 11 at 3:23
@CertainPerformance It's just contain all existing properties but not new properties which I added
– every Bit
Nov 11 at 3:27
Seems very odd, if theconsole.log
logs the proper value, but the returned object doesn't contain that property? Might be a problem in the consumer of the whole function
– CertainPerformance
Nov 11 at 3:34
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Hi I'm getting stuck with one problem that seem so easy :
I want to add new properties to an existing object, but it's not work proper
here my code :
challengeSearchNearBy: async function (longitude , latitude,min_distance,max_distance) {
var challengeNearBy = await Challenge.find({
location: {
$near: {
$geometry: { type: "Point", coordinates: [longitude, latitude] },
$minDistance: min_distance,
$maxDistance: max_distance
}
}
});//limit(30);
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
o.challenger_club_name = challenger_club.club_name;
o.challenger_club_avatar = challenger_club.avatar;
o.conqueror_club_name = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name;
o.conqueror_club_avatar = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
console.log(o.challenger_club_name); // this line logged what I want (challenger_club_name)
return o; // but this object not contain what I want (challenger_club_name, challenger_club_avatar ...)
});
const challenges = await Promise.all(challengesPromise);
return challenges;
},
javascript json object properties
Hi I'm getting stuck with one problem that seem so easy :
I want to add new properties to an existing object, but it's not work proper
here my code :
challengeSearchNearBy: async function (longitude , latitude,min_distance,max_distance) {
var challengeNearBy = await Challenge.find({
location: {
$near: {
$geometry: { type: "Point", coordinates: [longitude, latitude] },
$minDistance: min_distance,
$maxDistance: max_distance
}
}
});//limit(30);
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
o.challenger_club_name = challenger_club.club_name;
o.challenger_club_avatar = challenger_club.avatar;
o.conqueror_club_name = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name;
o.conqueror_club_avatar = ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
console.log(o.challenger_club_name); // this line logged what I want (challenger_club_name)
return o; // but this object not contain what I want (challenger_club_name, challenger_club_avatar ...)
});
const challenges = await Promise.all(challengesPromise);
return challenges;
},
javascript json object properties
javascript json object properties
asked Nov 11 at 3:08
every Bit
8019
8019
If all you want iso.challenger_club_name
, thenreturn o.challenger_club_name
?
– CertainPerformance
Nov 11 at 3:09
@CertainPerformance I want object o within new properties such as : challenger_club_name, challenger_club_avatar ...
– every Bit
Nov 11 at 3:12
What does it contain instead?
– CertainPerformance
Nov 11 at 3:23
@CertainPerformance It's just contain all existing properties but not new properties which I added
– every Bit
Nov 11 at 3:27
Seems very odd, if theconsole.log
logs the proper value, but the returned object doesn't contain that property? Might be a problem in the consumer of the whole function
– CertainPerformance
Nov 11 at 3:34
add a comment |
If all you want iso.challenger_club_name
, thenreturn o.challenger_club_name
?
– CertainPerformance
Nov 11 at 3:09
@CertainPerformance I want object o within new properties such as : challenger_club_name, challenger_club_avatar ...
– every Bit
Nov 11 at 3:12
What does it contain instead?
– CertainPerformance
Nov 11 at 3:23
@CertainPerformance It's just contain all existing properties but not new properties which I added
– every Bit
Nov 11 at 3:27
Seems very odd, if theconsole.log
logs the proper value, but the returned object doesn't contain that property? Might be a problem in the consumer of the whole function
– CertainPerformance
Nov 11 at 3:34
If all you want is
o.challenger_club_name
, then return o.challenger_club_name
?– CertainPerformance
Nov 11 at 3:09
If all you want is
o.challenger_club_name
, then return o.challenger_club_name
?– CertainPerformance
Nov 11 at 3:09
@CertainPerformance I want object o within new properties such as : challenger_club_name, challenger_club_avatar ...
– every Bit
Nov 11 at 3:12
@CertainPerformance I want object o within new properties such as : challenger_club_name, challenger_club_avatar ...
– every Bit
Nov 11 at 3:12
What does it contain instead?
– CertainPerformance
Nov 11 at 3:23
What does it contain instead?
– CertainPerformance
Nov 11 at 3:23
@CertainPerformance It's just contain all existing properties but not new properties which I added
– every Bit
Nov 11 at 3:27
@CertainPerformance It's just contain all existing properties but not new properties which I added
– every Bit
Nov 11 at 3:27
Seems very odd, if the
console.log
logs the proper value, but the returned object doesn't contain that property? Might be a problem in the consumer of the whole function– CertainPerformance
Nov 11 at 3:34
Seems very odd, if the
console.log
logs the proper value, but the returned object doesn't contain that property? Might be a problem in the consumer of the whole function– CertainPerformance
Nov 11 at 3:34
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Return new objects inside your map.
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
return {
...o,
challenger_club_name: challenger_club.club_name,
challenger_club_avatar: challenger_club.avatar,
conqueror_club_name: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name,
conqueror_club_avatar: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
}
});
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Return new objects inside your map.
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
return {
...o,
challenger_club_name: challenger_club.club_name,
challenger_club_avatar: challenger_club.avatar,
conqueror_club_name: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name,
conqueror_club_avatar: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
}
});
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
add a comment |
up vote
1
down vote
accepted
Return new objects inside your map.
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
return {
...o,
challenger_club_name: challenger_club.club_name,
challenger_club_avatar: challenger_club.avatar,
conqueror_club_name: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name,
conqueror_club_avatar: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
}
});
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Return new objects inside your map.
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
return {
...o,
challenger_club_name: challenger_club.club_name,
challenger_club_avatar: challenger_club.avatar,
conqueror_club_name: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name,
conqueror_club_avatar: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
}
});
Return new objects inside your map.
const challengesPromise = challengeNearBy.map(async function(o){
const challenger_club = await Club.findById(o.challenger_club_id);
const conqueror_club = await Club.findById(o.conqueror_club_id);
return {
...o,
challenger_club_name: challenger_club.club_name,
challenger_club_avatar: challenger_club.avatar,
conqueror_club_name: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.club_name,
conqueror_club_avatar: ObjectHelper.isNullOrUndefined(conqueror_club)? "":conqueror_club.avatar;
}
});
answered Nov 11 at 4:09
Ty Kroll
1,024821
1,024821
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
add a comment |
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
yeah, thank ! it's work :)
– every Bit
Nov 11 at 4:13
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245509%2fadd-new-properties-to-object-in-javascript-not-work-proper%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If all you want is
o.challenger_club_name
, thenreturn o.challenger_club_name
?– CertainPerformance
Nov 11 at 3:09
@CertainPerformance I want object o within new properties such as : challenger_club_name, challenger_club_avatar ...
– every Bit
Nov 11 at 3:12
What does it contain instead?
– CertainPerformance
Nov 11 at 3:23
@CertainPerformance It's just contain all existing properties but not new properties which I added
– every Bit
Nov 11 at 3:27
Seems very odd, if the
console.log
logs the proper value, but the returned object doesn't contain that property? Might be a problem in the consumer of the whole function– CertainPerformance
Nov 11 at 3:34