0

When I run this,

Module.find(function(err,Module){
  console.log(Module);
});

It returns data like

{ _id: 57f769b130bbaf129c586eb5, Name: 'Sydney', Status: true },
{ _id: 57f76e19f30d3c1ca02d002b, Name: 'zamora', Status: true },

How to get the data of Name and Status? and store it in a variable like in java.

String name = db.getString("Name");
1
  • In which variable you want to save it? don't forget that node.js is run in async nature so you need to take care about that.Otherwise you will get some weird scenario. Commented Oct 12, 2016 at 5:29

1 Answer 1

1

you can use for loop:

var Name=[];
var Status=[]; 

for(i=0;i<Module.length;i++) {
     console.log(Module[i].Name);
     console.log(Module[i].Status);
     Name[i] = Module[i].Name;
     Status[i]= Module[i].Status;
}

in this way, you can get data of Name and Status and store it.

Sign up to request clarification or add additional context in comments.

1 Comment

In this case user always get last element in array. I think you need to define it above loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.