Filter data in Object in JavaScript
I have the following object.
var Data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ]How to fetch data by a dermatologist from an object.
I'm trying the following code.
var result = Data['dermatologist']
But I got only one record.
I want all objects which contain the same dermatologist as.
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4021,
"owner_name": "John Doe",
"pet_name": "Dog",
"score": 37
,
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4023,
"owner_name": "James",
"pet_name": "Parrot",
"score": 50
javascript jquery
|
show 4 more comments
I have the following object.
var Data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ]How to fetch data by a dermatologist from an object.
I'm trying the following code.
var result = Data['dermatologist']
But I got only one record.
I want all objects which contain the same dermatologist as.
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4021,
"owner_name": "John Doe",
"pet_name": "Dog",
"score": 37
,
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4023,
"owner_name": "James",
"pet_name": "Parrot",
"score": 50
javascript jquery
Date!==Data
– Nina Scholz
Nov 12 at 8:06
You want all the dermatologists names?
– bambam
Nov 12 at 8:06
2
That object isn't remotely valid JavaScript.
– Quentin
Nov 12 at 8:07
Thanks, @NinaScholz I Edited the question.
– Muddasir23
Nov 12 at 8:08
1
@Muddasir23 — After your latest edit, the JS data structure still won't compile. You need to provide a real Minimal, Complete, and Verifiable example.
– Quentin
Nov 12 at 8:47
|
show 4 more comments
I have the following object.
var Data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ]How to fetch data by a dermatologist from an object.
I'm trying the following code.
var result = Data['dermatologist']
But I got only one record.
I want all objects which contain the same dermatologist as.
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4021,
"owner_name": "John Doe",
"pet_name": "Dog",
"score": 37
,
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4023,
"owner_name": "James",
"pet_name": "Parrot",
"score": 50
javascript jquery
I have the following object.
var Data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ]How to fetch data by a dermatologist from an object.
I'm trying the following code.
var result = Data['dermatologist']
But I got only one record.
I want all objects which contain the same dermatologist as.
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4021,
"owner_name": "John Doe",
"pet_name": "Dog",
"score": 37
,
"datetime": "03:48 PM 10/31/2018",
"dermatologist": "Canfield",
"id": 4023,
"owner_name": "James",
"pet_name": "Parrot",
"score": 50
var Data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ]var Data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ]javascript jquery
javascript jquery
edited Nov 12 at 12:40
asked Nov 12 at 8:04
Muddasir23
1089
1089
Date!==Data
– Nina Scholz
Nov 12 at 8:06
You want all the dermatologists names?
– bambam
Nov 12 at 8:06
2
That object isn't remotely valid JavaScript.
– Quentin
Nov 12 at 8:07
Thanks, @NinaScholz I Edited the question.
– Muddasir23
Nov 12 at 8:08
1
@Muddasir23 — After your latest edit, the JS data structure still won't compile. You need to provide a real Minimal, Complete, and Verifiable example.
– Quentin
Nov 12 at 8:47
|
show 4 more comments
Date!==Data
– Nina Scholz
Nov 12 at 8:06
You want all the dermatologists names?
– bambam
Nov 12 at 8:06
2
That object isn't remotely valid JavaScript.
– Quentin
Nov 12 at 8:07
Thanks, @NinaScholz I Edited the question.
– Muddasir23
Nov 12 at 8:08
1
@Muddasir23 — After your latest edit, the JS data structure still won't compile. You need to provide a real Minimal, Complete, and Verifiable example.
– Quentin
Nov 12 at 8:47
Date !== Data– Nina Scholz
Nov 12 at 8:06
Date !== Data– Nina Scholz
Nov 12 at 8:06
You want all the dermatologists names?
– bambam
Nov 12 at 8:06
You want all the dermatologists names?
– bambam
Nov 12 at 8:06
2
2
That object isn't remotely valid JavaScript.
– Quentin
Nov 12 at 8:07
That object isn't remotely valid JavaScript.
– Quentin
Nov 12 at 8:07
Thanks, @NinaScholz I Edited the question.
– Muddasir23
Nov 12 at 8:08
Thanks, @NinaScholz I Edited the question.
– Muddasir23
Nov 12 at 8:08
1
1
@Muddasir23 — After your latest edit, the JS data structure still won't compile. You need to provide a real Minimal, Complete, and Verifiable example.
– Quentin
Nov 12 at 8:47
@Muddasir23 — After your latest edit, the JS data structure still won't compile. You need to provide a real Minimal, Complete, and Verifiable example.
– Quentin
Nov 12 at 8:47
|
show 4 more comments
3 Answers
3
active
oldest
votes
Assuming, you want to filter the array by known value of a specific key, then you coukd take the property and check against the value for a filtered result set.
Techniques used:
An
Arrayfor data andArray#filterfor filtering by using anarrow function with a
destructuring assignment for the property
dermatologistof each object and a check withIdentity/strict equality operator
===and the wanted value.
var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0;
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
add a comment |
Use Array.map() with object destructuring to get the dermatologist array:
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);
1
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said thatvar result = Date['dermatologist']returns one record.
– Quentin
Nov 12 at 8:09
1
I think OP just guessed that because you see that the variable name isDateand OP has given the structure with variable namedata
– Ankit Agarwal
Nov 12 at 8:12
@Quentin I think anyone can determine OP meant to writeDatajust by looking at the code.
– Roj
Nov 12 at 8:37
@Roj — It seems fairly obvious up until you get to the bit in the question wherevar result = Data['dermatologist']successfully gets one record.
– Quentin
Nov 12 at 8:39
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
|
show 1 more comment
Your JSON object needs to be edited so that it can be parsed correctly. I have assumed that your Data variable is an array of JSON objects, each of which has a property dermatologist. You can access any of the array elements like so: Data[i].dermatologist
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
Now it is easy to set up a for loop to iterate through all of the elements and do whatever is required to each element.
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
add a comment |
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
);
);
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%2f53257987%2ffilter-data-in-object-in-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming, you want to filter the array by known value of a specific key, then you coukd take the property and check against the value for a filtered result set.
Techniques used:
An
Arrayfor data andArray#filterfor filtering by using anarrow function with a
destructuring assignment for the property
dermatologistof each object and a check withIdentity/strict equality operator
===and the wanted value.
var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0;
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
add a comment |
Assuming, you want to filter the array by known value of a specific key, then you coukd take the property and check against the value for a filtered result set.
Techniques used:
An
Arrayfor data andArray#filterfor filtering by using anarrow function with a
destructuring assignment for the property
dermatologistof each object and a check withIdentity/strict equality operator
===and the wanted value.
var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0;
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
add a comment |
Assuming, you want to filter the array by known value of a specific key, then you coukd take the property and check against the value for a filtered result set.
Techniques used:
An
Arrayfor data andArray#filterfor filtering by using anarrow function with a
destructuring assignment for the property
dermatologistof each object and a check withIdentity/strict equality operator
===and the wanted value.
var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0; Assuming, you want to filter the array by known value of a specific key, then you coukd take the property and check against the value for a filtered result set.
Techniques used:
An
Arrayfor data andArray#filterfor filtering by using anarrow function with a
destructuring assignment for the property
dermatologistof each object and a check withIdentity/strict equality operator
===and the wanted value.
var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0; var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0; var data = [ datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4021, owner_name: "John Doe", pet_name: "Dog", score: 37 , datetime: "03:48 PM 10/31/2018", dermatologist: "Nicky barown", id: 4022, owner_name: "Carlos", pet_name: "Cat", score: "57" , datetime: "03:48 PM 10/31/2018", dermatologist: "Canfield", id: 4023, owner_name: "James", pet_name: "Parrot", score: 50 ],
result = data.filter(( dermatologist ) => dermatologist === "Canfield");
console.log(result);.as-console-wrapper max-height: 100% !important; top: 0; answered Nov 12 at 9:57
Nina Scholz
174k1387152
174k1387152
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
add a comment |
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
Thanks, it's easy for me to implement and works like a charm.
– Muddasir23
Nov 12 at 10:13
add a comment |
Use Array.map() with object destructuring to get the dermatologist array:
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);
1
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said thatvar result = Date['dermatologist']returns one record.
– Quentin
Nov 12 at 8:09
1
I think OP just guessed that because you see that the variable name isDateand OP has given the structure with variable namedata
– Ankit Agarwal
Nov 12 at 8:12
@Quentin I think anyone can determine OP meant to writeDatajust by looking at the code.
– Roj
Nov 12 at 8:37
@Roj — It seems fairly obvious up until you get to the bit in the question wherevar result = Data['dermatologist']successfully gets one record.
– Quentin
Nov 12 at 8:39
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
|
show 1 more comment
Use Array.map() with object destructuring to get the dermatologist array:
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);
1
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said thatvar result = Date['dermatologist']returns one record.
– Quentin
Nov 12 at 8:09
1
I think OP just guessed that because you see that the variable name isDateand OP has given the structure with variable namedata
– Ankit Agarwal
Nov 12 at 8:12
@Quentin I think anyone can determine OP meant to writeDatajust by looking at the code.
– Roj
Nov 12 at 8:37
@Roj — It seems fairly obvious up until you get to the bit in the question wherevar result = Data['dermatologist']successfully gets one record.
– Quentin
Nov 12 at 8:39
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
|
show 1 more comment
Use Array.map() with object destructuring to get the dermatologist array:
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);Use Array.map() with object destructuring to get the dermatologist array:
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
var dermatologists = Data.map((dermatologist) => dermatologist);
console.log(dermatologists);answered Nov 12 at 8:06
Ankit Agarwal
23.6k52044
23.6k52044
1
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said thatvar result = Date['dermatologist']returns one record.
– Quentin
Nov 12 at 8:09
1
I think OP just guessed that because you see that the variable name isDateand OP has given the structure with variable namedata
– Ankit Agarwal
Nov 12 at 8:12
@Quentin I think anyone can determine OP meant to writeDatajust by looking at the code.
– Roj
Nov 12 at 8:37
@Roj — It seems fairly obvious up until you get to the bit in the question wherevar result = Data['dermatologist']successfully gets one record.
– Quentin
Nov 12 at 8:39
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
|
show 1 more comment
1
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said thatvar result = Date['dermatologist']returns one record.
– Quentin
Nov 12 at 8:09
1
I think OP just guessed that because you see that the variable name isDateand OP has given the structure with variable namedata
– Ankit Agarwal
Nov 12 at 8:12
@Quentin I think anyone can determine OP meant to writeDatajust by looking at the code.
– Roj
Nov 12 at 8:37
@Roj — It seems fairly obvious up until you get to the bit in the question wherevar result = Data['dermatologist']successfully gets one record.
– Quentin
Nov 12 at 8:39
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
1
1
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said that
var result = Date['dermatologist'] returns one record.– Quentin
Nov 12 at 8:09
The data structure in the question is invalid, so you've had to guess at what the real data structure is. What you have can't be what the OP has because they said that
var result = Date['dermatologist'] returns one record.– Quentin
Nov 12 at 8:09
1
1
I think OP just guessed that because you see that the variable name is
Date and OP has given the structure with variable name data– Ankit Agarwal
Nov 12 at 8:12
I think OP just guessed that because you see that the variable name is
Date and OP has given the structure with variable name data– Ankit Agarwal
Nov 12 at 8:12
@Quentin I think anyone can determine OP meant to write
Data just by looking at the code.– Roj
Nov 12 at 8:37
@Quentin I think anyone can determine OP meant to write
Data just by looking at the code.– Roj
Nov 12 at 8:37
@Roj — It seems fairly obvious up until you get to the bit in the question where
var result = Data['dermatologist'] successfully gets one record.– Quentin
Nov 12 at 8:39
@Roj — It seems fairly obvious up until you get to the bit in the question where
var result = Data['dermatologist'] successfully gets one record.– Quentin
Nov 12 at 8:39
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
@Quentin true. But there's nothing wrong with asking for clarification or pushing someone in the right direction by giving better alternatives rather than shutting them down.
– Roj
Nov 12 at 8:45
|
show 1 more comment
Your JSON object needs to be edited so that it can be parsed correctly. I have assumed that your Data variable is an array of JSON objects, each of which has a property dermatologist. You can access any of the array elements like so: Data[i].dermatologist
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
Now it is easy to set up a for loop to iterate through all of the elements and do whatever is required to each element.
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
add a comment |
Your JSON object needs to be edited so that it can be parsed correctly. I have assumed that your Data variable is an array of JSON objects, each of which has a property dermatologist. You can access any of the array elements like so: Data[i].dermatologist
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
Now it is easy to set up a for loop to iterate through all of the elements and do whatever is required to each element.
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
add a comment |
Your JSON object needs to be edited so that it can be parsed correctly. I have assumed that your Data variable is an array of JSON objects, each of which has a property dermatologist. You can access any of the array elements like so: Data[i].dermatologist
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
Now it is easy to set up a for loop to iterate through all of the elements and do whatever is required to each element.
Your JSON object needs to be edited so that it can be parsed correctly. I have assumed that your Data variable is an array of JSON objects, each of which has a property dermatologist. You can access any of the array elements like so: Data[i].dermatologist
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
Now it is easy to set up a for loop to iterate through all of the elements and do whatever is required to each element.
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
var Data = [
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4021",
owner_name: "John Doe",
pet_name: "Dog",
score: "37"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Nicky barown",
id: "4022",
owner_name: "Carlos",
pet_name: "Cat",
score: "57"
,
datetime: "03:48 PM 10/31/2018",
dermatologist: "Canfield",
id: "4023",
owner_name: "James",
pet_name: "Parrot",
score: "50"
];
console.log(Data[0].dermatologist); //Canfield
console.log(Data[1].dermatologist); //Nicky barown
//alternatively:
console.log(Data[2]["dermatologist"]); //Canfield
edited Nov 12 at 8:21
answered Nov 12 at 8:18
Ahmad
8,18843463
8,18843463
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
add a comment |
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
read the question carefully. thanks for the help.
– Muddasir23
Nov 12 at 8:21
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2f53257987%2ffilter-data-in-object-in-javascript%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
Date!==Data– Nina Scholz
Nov 12 at 8:06
You want all the dermatologists names?
– bambam
Nov 12 at 8:06
2
That object isn't remotely valid JavaScript.
– Quentin
Nov 12 at 8:07
Thanks, @NinaScholz I Edited the question.
– Muddasir23
Nov 12 at 8:08
1
@Muddasir23 — After your latest edit, the JS data structure still won't compile. You need to provide a real Minimal, Complete, and Verifiable example.
– Quentin
Nov 12 at 8:47