Accessing data within objectLength of a JavaScript objectDetecting an undefined object propertyWhat is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How do I test for an empty JavaScript object?How do I correctly clone a JavaScript object?Checking if a key exists in a JavaScript object?Storing Objects in HTML5 localStorageHow to check if an object is an array?

Island of Knights, Knaves and Spies

How do I reattach a shelf to the wall when it ripped out of the wall?

Creating a chemical industry from a medieval tech level without petroleum

Can someone publish a story that happened to you?

My bank got bought out, am I now going to have to start filing tax returns in a different state?

What is the unit of time_lock_delta in LND?

How to pronounce 'c++' in Spanish

My admission is revoked after accepting the admission offer

Is Diceware more secure than a long passphrase?

As an international instructor, should I openly talk about my accent?

What is purpose of DB Browser(dbbrowser.aspx) under admin tool?

A ​Note ​on ​N!

Find a stone which is not the lightest one

Restricting the options of a lookup field, based on the value of another lookup field?

Check if a string is entirely made of the same substring

Nails holding drywall

A Paper Record is What I Hamper

Where was the County of Thurn und Taxis located?

"The cow" OR "a cow" OR "cows" in this context

What to do with someone that cheated their way through university and a PhD program?

Why do games have consumables?

Is there metaphorical meaning of "aus der Haft entlassen"?

What is the best way to deal with NPC-NPC combat?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?



Accessing data within object


Length of a JavaScript objectDetecting an undefined object propertyWhat is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How do I test for an empty JavaScript object?How do I correctly clone a JavaScript object?Checking if a key exists in a JavaScript object?Storing Objects in HTML5 localStorageHow to check if an object is an array?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















app.get('/profile/:id', function(req, res)
var options = method: 'GET',
url: 'https://api.favoriot.com/v1/streams?max=1',
headers:
'cache-control': 'no-cache',
'content-type': 'application/json',
'apikey': 'api key' ;

request(options, function (error, response, body)
res.render('profile', data:body);
console.log(body)
);
);


when I run code above, I get this data:




"debugCode":null,"statusCode":200,"numFound":1,"results":["user_id":"xxx510","stream_created_at":"2019-03-05T16:13:01.982Z","stream_developer_id":"f8b8fcb9-6f3e-4138-8c6b-d0a7e8xxxxx@xxxx510","device_developer_id":"raspberryPIxx@xxx510","data":"distance":"12.4","status":"1"]




how can I make it only display status only?










share|improve this question
























  • There's no middleware used in this code and you can access status from response.statusCode

    – Kiran Mathew Mohan
    Mar 22 at 17:30











  • sorry about that, I'm new in node.js. I try using response.statusCode before and I get the response. but the status that I want is inside data: ,"data":"distance":"12.4","status":"1"}}]}. I try using response.results[0].data.status but i receive error Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:57











  • AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their (API playground)[api.favoriot.com/docs/#!/Data/listStreams] by setting your API key on it.

    – Kiran Mathew Mohan
    Mar 23 at 7:07

















-1















app.get('/profile/:id', function(req, res)
var options = method: 'GET',
url: 'https://api.favoriot.com/v1/streams?max=1',
headers:
'cache-control': 'no-cache',
'content-type': 'application/json',
'apikey': 'api key' ;

request(options, function (error, response, body)
res.render('profile', data:body);
console.log(body)
);
);


when I run code above, I get this data:




"debugCode":null,"statusCode":200,"numFound":1,"results":["user_id":"xxx510","stream_created_at":"2019-03-05T16:13:01.982Z","stream_developer_id":"f8b8fcb9-6f3e-4138-8c6b-d0a7e8xxxxx@xxxx510","device_developer_id":"raspberryPIxx@xxx510","data":"distance":"12.4","status":"1"]




how can I make it only display status only?










share|improve this question
























  • There's no middleware used in this code and you can access status from response.statusCode

    – Kiran Mathew Mohan
    Mar 22 at 17:30











  • sorry about that, I'm new in node.js. I try using response.statusCode before and I get the response. but the status that I want is inside data: ,"data":"distance":"12.4","status":"1"}}]}. I try using response.results[0].data.status but i receive error Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:57











  • AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their (API playground)[api.favoriot.com/docs/#!/Data/listStreams] by setting your API key on it.

    – Kiran Mathew Mohan
    Mar 23 at 7:07













-1












-1








-1


0






app.get('/profile/:id', function(req, res)
var options = method: 'GET',
url: 'https://api.favoriot.com/v1/streams?max=1',
headers:
'cache-control': 'no-cache',
'content-type': 'application/json',
'apikey': 'api key' ;

request(options, function (error, response, body)
res.render('profile', data:body);
console.log(body)
);
);


when I run code above, I get this data:




"debugCode":null,"statusCode":200,"numFound":1,"results":["user_id":"xxx510","stream_created_at":"2019-03-05T16:13:01.982Z","stream_developer_id":"f8b8fcb9-6f3e-4138-8c6b-d0a7e8xxxxx@xxxx510","device_developer_id":"raspberryPIxx@xxx510","data":"distance":"12.4","status":"1"]




how can I make it only display status only?










share|improve this question
















app.get('/profile/:id', function(req, res)
var options = method: 'GET',
url: 'https://api.favoriot.com/v1/streams?max=1',
headers:
'cache-control': 'no-cache',
'content-type': 'application/json',
'apikey': 'api key' ;

request(options, function (error, response, body)
res.render('profile', data:body);
console.log(body)
);
);


when I run code above, I get this data:




"debugCode":null,"statusCode":200,"numFound":1,"results":["user_id":"xxx510","stream_created_at":"2019-03-05T16:13:01.982Z","stream_developer_id":"f8b8fcb9-6f3e-4138-8c6b-d0a7e8xxxxx@xxxx510","device_developer_id":"raspberryPIxx@xxx510","data":"distance":"12.4","status":"1"]




how can I make it only display status only?







javascript node.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 17:59









Isaac Vidrine

898215




898215










asked Mar 22 at 16:45









ASYRAFUDDIN MOHAMADASYRAFUDDIN MOHAMAD

32




32












  • There's no middleware used in this code and you can access status from response.statusCode

    – Kiran Mathew Mohan
    Mar 22 at 17:30











  • sorry about that, I'm new in node.js. I try using response.statusCode before and I get the response. but the status that I want is inside data: ,"data":"distance":"12.4","status":"1"}}]}. I try using response.results[0].data.status but i receive error Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:57











  • AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their (API playground)[api.favoriot.com/docs/#!/Data/listStreams] by setting your API key on it.

    – Kiran Mathew Mohan
    Mar 23 at 7:07

















  • There's no middleware used in this code and you can access status from response.statusCode

    – Kiran Mathew Mohan
    Mar 22 at 17:30











  • sorry about that, I'm new in node.js. I try using response.statusCode before and I get the response. but the status that I want is inside data: ,"data":"distance":"12.4","status":"1"}}]}. I try using response.results[0].data.status but i receive error Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:57











  • AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their (API playground)[api.favoriot.com/docs/#!/Data/listStreams] by setting your API key on it.

    – Kiran Mathew Mohan
    Mar 23 at 7:07
















There's no middleware used in this code and you can access status from response.statusCode

– Kiran Mathew Mohan
Mar 22 at 17:30





There's no middleware used in this code and you can access status from response.statusCode

– Kiran Mathew Mohan
Mar 22 at 17:30













sorry about that, I'm new in node.js. I try using response.statusCode before and I get the response. but the status that I want is inside data: ,"data":"distance":"12.4","status":"1"}}]}. I try using response.results[0].data.status but i receive error Cannot read property '0' of undefined

– ASYRAFUDDIN MOHAMAD
Mar 23 at 2:57





sorry about that, I'm new in node.js. I try using response.statusCode before and I get the response. but the status that I want is inside data: ,"data":"distance":"12.4","status":"1"}}]}. I try using response.results[0].data.status but i receive error Cannot read property '0' of undefined

– ASYRAFUDDIN MOHAMAD
Mar 23 at 2:57













AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their (API playground)[api.favoriot.com/docs/#!/Data/listStreams] by setting your API key on it.

– Kiran Mathew Mohan
Mar 23 at 7:07





AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their (API playground)[api.favoriot.com/docs/#!/Data/listStreams] by setting your API key on it.

– Kiran Mathew Mohan
Mar 23 at 7:07












2 Answers
2






active

oldest

votes


















0














AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their API playground by setting your API key on it. I have rewritten the code using ES6 standards by promisifying request module or you can use the request-promise-native.



function requestPromisified(options) 
return new Promise(function(resolve, reject)
request(options, function(error, res, body)
if (!error && res.statusCode == 200)
resolve(body);
else
reject(error);

);
);


app.get("/profile/:id", async (req, res) =>
const options =
method: "GET",
url: "https://api.favoriot.com/v1/streams?max=1",
headers:
"cache-control": "no-cache",
"content-type": "application/json",
apikey: "api key"

;
try
const body = await requestPromisified(options);
console.log(body);
res.render("profile", data: body );
catch (error)
res.status(400).send('Unable to find a profile')

);





share|improve this answer























  • I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

    – ASYRAFUDDIN MOHAMAD
    Mar 26 at 2:28


















0














1) There is no middleware in this example... you're just making a call to get some data.



2) status is available in body.results[0].data.status so just use that instead of the entire body object






share|improve this answer

























  • sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:59











  • that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

    – Kiran Mathew Mohan
    Mar 23 at 7:12











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304271%2faccessing-data-within-object%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their API playground by setting your API key on it. I have rewritten the code using ES6 standards by promisifying request module or you can use the request-promise-native.



function requestPromisified(options) 
return new Promise(function(resolve, reject)
request(options, function(error, res, body)
if (!error && res.statusCode == 200)
resolve(body);
else
reject(error);

);
);


app.get("/profile/:id", async (req, res) =>
const options =
method: "GET",
url: "https://api.favoriot.com/v1/streams?max=1",
headers:
"cache-control": "no-cache",
"content-type": "application/json",
apikey: "api key"

;
try
const body = await requestPromisified(options);
console.log(body);
res.render("profile", data: body );
catch (error)
res.status(400).send('Unable to find a profile')

);





share|improve this answer























  • I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

    – ASYRAFUDDIN MOHAMAD
    Mar 26 at 2:28















0














AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their API playground by setting your API key on it. I have rewritten the code using ES6 standards by promisifying request module or you can use the request-promise-native.



function requestPromisified(options) 
return new Promise(function(resolve, reject)
request(options, function(error, res, body)
if (!error && res.statusCode == 200)
resolve(body);
else
reject(error);

);
);


app.get("/profile/:id", async (req, res) =>
const options =
method: "GET",
url: "https://api.favoriot.com/v1/streams?max=1",
headers:
"cache-control": "no-cache",
"content-type": "application/json",
apikey: "api key"

;
try
const body = await requestPromisified(options);
console.log(body);
res.render("profile", data: body );
catch (error)
res.status(400).send('Unable to find a profile')

);





share|improve this answer























  • I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

    – ASYRAFUDDIN MOHAMAD
    Mar 26 at 2:28













0












0








0







AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their API playground by setting your API key on it. I have rewritten the code using ES6 standards by promisifying request module or you can use the request-promise-native.



function requestPromisified(options) 
return new Promise(function(resolve, reject)
request(options, function(error, res, body)
if (!error && res.statusCode == 200)
resolve(body);
else
reject(error);

);
);


app.get("/profile/:id", async (req, res) =>
const options =
method: "GET",
url: "https://api.favoriot.com/v1/streams?max=1",
headers:
"cache-control": "no-cache",
"content-type": "application/json",
apikey: "api key"

;
try
const body = await requestPromisified(options);
console.log(body);
res.render("profile", data: body );
catch (error)
res.status(400).send('Unable to find a profile')

);





share|improve this answer













AFAIK there is no issue with the code as such. Are you sure that you got the distance and status in the data field of body or is it the intended output? By try using their API playground by setting your API key on it. I have rewritten the code using ES6 standards by promisifying request module or you can use the request-promise-native.



function requestPromisified(options) 
return new Promise(function(resolve, reject)
request(options, function(error, res, body)
if (!error && res.statusCode == 200)
resolve(body);
else
reject(error);

);
);


app.get("/profile/:id", async (req, res) =>
const options =
method: "GET",
url: "https://api.favoriot.com/v1/streams?max=1",
headers:
"cache-control": "no-cache",
"content-type": "application/json",
apikey: "api key"

;
try
const body = await requestPromisified(options);
console.log(body);
res.render("profile", data: body );
catch (error)
res.status(400).send('Unable to find a profile')

);






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 13:51









Kiran Mathew MohanKiran Mathew Mohan

640415




640415












  • I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

    – ASYRAFUDDIN MOHAMAD
    Mar 26 at 2:28

















  • I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

    – ASYRAFUDDIN MOHAMAD
    Mar 26 at 2:28
















I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

– ASYRAFUDDIN MOHAMAD
Mar 26 at 2:28





I manage to solve it. I need to parse it as object first. I add JSON.parse(body) and it solve. thanks for the help

– ASYRAFUDDIN MOHAMAD
Mar 26 at 2:28













0














1) There is no middleware in this example... you're just making a call to get some data.



2) status is available in body.results[0].data.status so just use that instead of the entire body object






share|improve this answer

























  • sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:59











  • that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

    – Kiran Mathew Mohan
    Mar 23 at 7:12















0














1) There is no middleware in this example... you're just making a call to get some data.



2) status is available in body.results[0].data.status so just use that instead of the entire body object






share|improve this answer

























  • sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:59











  • that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

    – Kiran Mathew Mohan
    Mar 23 at 7:12













0












0








0







1) There is no middleware in this example... you're just making a call to get some data.



2) status is available in body.results[0].data.status so just use that instead of the entire body object






share|improve this answer















1) There is no middleware in this example... you're just making a call to get some data.



2) status is available in body.results[0].data.status so just use that instead of the entire body object







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 17:01

























answered Mar 22 at 16:55









Isaac VidrineIsaac Vidrine

898215




898215












  • sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:59











  • that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

    – Kiran Mathew Mohan
    Mar 23 at 7:12

















  • sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

    – ASYRAFUDDIN MOHAMAD
    Mar 23 at 2:59











  • that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

    – Kiran Mathew Mohan
    Mar 23 at 7:12
















sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

– ASYRAFUDDIN MOHAMAD
Mar 23 at 2:59





sorry about that, I'm new in node.js. i already use that but i got an error :Cannot read property '0' of undefined

– ASYRAFUDDIN MOHAMAD
Mar 23 at 2:59













that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

– Kiran Mathew Mohan
Mar 23 at 7:12





that usually means results property is not defined for body, you might be encountering an error, so add if(error) console.log(error) before your res.render()

– Kiran Mathew Mohan
Mar 23 at 7:12

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304271%2faccessing-data-within-object%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript