Find specific item in an array? [duplicate] - javascript

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 3 years ago.
I have an array that looks like this:
cardNumber: "2344234454562036"
cardType: "Visa"
cardholderName: "Yeyy"
cvv: "123"
expiryMonth: 12
expiryYear: 2022
postalCode: "52636"
redactedCardNumber: "••••••••••••2036"
__proto__: —'
I need to get the value of redactedCardNumber from that array.
The first thing that I am confused about is that when i print the above 'array' in the console, it actually show an object before everything! so is this an array or an object?
also, what is the best way of getting the specific item like 'redactedCardNumber' from it?

It looks like an object. If so, you can access it by obj.redactedCardNumber.

Related

Is there a way to log a JS object except for one key in it? [duplicate]

This question already has answers here:
How can I clone a JavaScript object except for one key?
(25 answers)
Closed 6 months ago.
I have a JS object that i want to log to the console but one of its values is 5 million characters of a hashed image so im not really interessted in that. Is there a way to exclude this key from the console log / is there a short form for cloning the object, deleting the value and logging it?
Not a duplicate of "cloning object except for one key" btw
One very easy way to do this is by using the spread operator [MDN Docs]
const yourObject = {id:"something",img: "5M-character-stuff"}
console.log({...yourObject, img: "short-img"});
// logs: {id:"something",img: "short-img"}

Read from JSON where the name is [duplicate]

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 1 year ago.
My resultjson's content:
[{"name":"Dummy","id":"780828872962080819","sync_code":123456,"expiration":"2021-04-07T14:03:34.000Z"}]
I need the "name" from the JSON as a String, i tried with JSON.parse(resultjson).name but it didnt work.
It's an array. You need to access an element:
JSON.parse(resultjson)[0 /* or other element */].name

How calling right JSON for JavaScript [duplicate]

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 2 years ago.
I have a problem with calling the appropriate parameters for my function from this DOM:
data
weather:Array(1)
0: {id:800, main:"Clouds", description: "few clouds", icon: "02n"}
I write this (but it doesn'work):
$(".myClass").html(data.weather:Array(1).0.description);
How I must write this code to get description?
You were not accessing array properly. Try it.
$(".myClass").html(data.weather[0].description);

How do I get the value of a # object attribute? [duplicate]

This question already has answers here:
How to access object property with invalid characters
(2 answers)
Closed 7 years ago.
So I'm getting some JSON data containing 12 objects. outputting the objects to console shows me:
Object{ (...) }
#categoryID: "123"
#id: "234"
categoryTitle: "abc"
(...)
If I want to fetch the category title, I simply do item.categoryTitle. But if I want the ID, I can't use item.id.
According to this answer, one can use $object->{'#id'};, but trying $item->{'#id'} is not working.
So how to I get this value?
Refer it using ['key'] syntax
var obj = { '#id' : 123 };
console.log(obj['#id']); //123

Underscore.js get value of key object in array of object [duplicate]

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 7 years ago.
i have to get the value of wave1 and wave2 from array by using underscore.js
array =[{"id":1,"name":"Monoprix", "pdv":16,"graph":[{"wave1":22,"wave2":11}]} ;
i try
$scope.wave1 =array.graph.wave1 ;
console.log($scope.wave1) ;
console log = Unidentified
can you help me !
your code is wrong, you miss ] after element list.
your array :
var array =[{"id":1,"name":"Monoprix", "pdv":16,"graph":[{"wave1":22,"wave2":11}]}];
and to get some data you must first select array index, like this:
array[0].graph

Categories