167
rated 0 times
[
170]
[
3]
/ answers: 1 / hits: 18815
/ 7 Years ago, fri, march 10, 2017, 12:00:00
Working on JavaScript app and need help in creating a new object from response received from ajax call.
The output received is array of objects, sample format below:
{
items: [
{
id: 02egnc0eo7qk53e9nh7igq6d48,
summary: Learn to swim,
start: {
dateTime: 2017-03-04T19:00:00+05:30
}
}
]
}
However, my component expects JS Object in the following format:
{
id: e1,
title: Express,
start: Jan 13, 2010,
description: Jan 13, 2010
}
Is following approach correct, please suggest better approach if any
var content = {
items: [{
id: 02egnc0eo7qk53e9nh7igq6d48,
summary: Learn to code,
start: {
dateTime: 2017-03-04T19:00:00+05:30
}
}
}
};
var gcalEvents = {};
var jsonObj = {
id: e1,
title: Oracle Application Express,
start: Jan 13, 2010,
description: Jan 13, 2010
};
console.log(content.items.length);
for (var index = 0; index < content.items.length; index++) {
var obj = content.items;
console.log(obj);
jsonObj.id = obj[index][id];
jsonObj.title = obj[index].summary;
jsonObj.start = obj[index].start.dateTime;
jsonObj.description = ;
console.log(jsonObj);
gcalEvents[index] = jsonObj;
}
console.log(gcalEvents);
More From » json