How to check if a key is empty or not in an array of objects? [duplicate]How do I check if all elements of an array are null?Check if all elements satisfy a conditionHow do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How to append something to an array?Checking if a key exists in a JavaScript object?How do I empty an array in JavaScript?How to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

My employer wants me to do a work of 6 months in just 2 months

Random point on a sphere

Do any aircraft carry boats?

Tall red piece with coffee cup, phone and gas picture?

Why should I always enable compiler warnings?

Is English tonal for some words, like "permit"?

Insert str into larger str in the most pythonic way

Is there a star over my head?

Are programming languages necessary/useful for operations research practitioner?

Using the pipe operator ("|") when executing system commands

How can I maximize the impact of my charitable donations?

Writing a worded mathematical expression

How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?

Can I cast Sunbeam if both my hands are busy?

Long list of Hit and Get from sudo apt update

Who are the two thieves that appear the opening of Batman: TAS?

Are there any space probes or landers which regained communication after being lost?

Can I disable a battery powered device by reversing half of its batteries?

SCOTUS - Can Congress overrule Marbury v. Madison by statute?

A Little Riddle

I asked for a graduate student position from a professor. He replied "welcome". What does that mean?

Do Milankovitch Cycles fully explain climate change?

How do I politely hint customers to leave my store, without pretending to need leave store myself?

How do email clients "send later" without storing a password?



How to check if a key is empty or not in an array of objects? [duplicate]


How do I check if all elements of an array are null?Check if all elements satisfy a conditionHow do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How to append something to an array?Checking if a key exists in a JavaScript object?How do I empty an array in JavaScript?How to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1
















This question already has an answer here:



  • How do I check if all elements of an array are null?

    3 answers



I am doing react native application. And I am getting json response like below.



[

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

]


I have to check all the value properties are empty or not. If all are empty, I have to do some action else condition other action.



 const emptyValues = sortedData.map(value => value.key);
console.log('emptyValues data', emptyValues);









share|improve this question
















marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 28 at 9:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Note: I'm aware linked question checks for null and this post asks for empty values. However, the logic is same and approaches defined addresses solution for it

    – Rajesh
    Mar 28 at 9:25

















1
















This question already has an answer here:



  • How do I check if all elements of an array are null?

    3 answers



I am doing react native application. And I am getting json response like below.



[

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

]


I have to check all the value properties are empty or not. If all are empty, I have to do some action else condition other action.



 const emptyValues = sortedData.map(value => value.key);
console.log('emptyValues data', emptyValues);









share|improve this question
















marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 28 at 9:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Note: I'm aware linked question checks for null and this post asks for empty values. However, the logic is same and approaches defined addresses solution for it

    – Rajesh
    Mar 28 at 9:25













1












1








1


1







This question already has an answer here:



  • How do I check if all elements of an array are null?

    3 answers



I am doing react native application. And I am getting json response like below.



[

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

]


I have to check all the value properties are empty or not. If all are empty, I have to do some action else condition other action.



 const emptyValues = sortedData.map(value => value.key);
console.log('emptyValues data', emptyValues);









share|improve this question

















This question already has an answer here:



  • How do I check if all elements of an array are null?

    3 answers



I am doing react native application. And I am getting json response like below.



[

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

]


I have to check all the value properties are empty or not. If all are empty, I have to do some action else condition other action.



 const emptyValues = sortedData.map(value => value.key);
console.log('emptyValues data', emptyValues);




This question already has an answer here:



  • How do I check if all elements of an array are null?

    3 answers







javascript arrays react-native






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 9:43









adiga

20.6k7 gold badges30 silver badges52 bronze badges




20.6k7 gold badges30 silver badges52 bronze badges










asked Mar 28 at 9:02









Anilkumar iOS ReactNativeAnilkumar iOS ReactNative

1,2802 gold badges18 silver badges46 bronze badges




1,2802 gold badges18 silver badges46 bronze badges





marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 28 at 9:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 28 at 9:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 28 at 9:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Note: I'm aware linked question checks for null and this post asks for empty values. However, the logic is same and approaches defined addresses solution for it

    – Rajesh
    Mar 28 at 9:25

















  • Note: I'm aware linked question checks for null and this post asks for empty values. However, the logic is same and approaches defined addresses solution for it

    – Rajesh
    Mar 28 at 9:25
















Note: I'm aware linked question checks for null and this post asks for empty values. However, the logic is same and approaches defined addresses solution for it

– Rajesh
Mar 28 at 9:25





Note: I'm aware linked question checks for null and this post asks for empty values. However, the logic is same and approaches defined addresses solution for it

– Rajesh
Mar 28 at 9:25












2 Answers
2






active

oldest

votes


















3
















Use Array.every() to check if all value keys are '0' (or whatever your definition of empty is):






const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)








share|improve this answer



























  • My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

    – Rajesh
    Mar 28 at 9:29











  • Will this returns true or false? And this will check all the indexes, right?

    – Anilkumar iOS ReactNative
    Mar 28 at 9:46












  • But, Its always returning false? even the values are 0

    – Anilkumar iOS ReactNative
    Mar 28 at 9:49












  • What is your definition of empty?

    – Ori Drori
    Mar 28 at 9:51






  • 1





    Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

    – Ori Drori
    Mar 28 at 9:55


















-1
















let arr = [

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

];

let desiredVal = arr.map((obj) =>
if(obj.value)
//do something

);





share|improve this answer




















  • 2





    Just a general suggestion, an answer is incomplete without explanation.

    – Rajesh
    Mar 28 at 9:30




















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3
















Use Array.every() to check if all value keys are '0' (or whatever your definition of empty is):






const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)








share|improve this answer



























  • My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

    – Rajesh
    Mar 28 at 9:29











  • Will this returns true or false? And this will check all the indexes, right?

    – Anilkumar iOS ReactNative
    Mar 28 at 9:46












  • But, Its always returning false? even the values are 0

    – Anilkumar iOS ReactNative
    Mar 28 at 9:49












  • What is your definition of empty?

    – Ori Drori
    Mar 28 at 9:51






  • 1





    Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

    – Ori Drori
    Mar 28 at 9:55















3
















Use Array.every() to check if all value keys are '0' (or whatever your definition of empty is):






const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)








share|improve this answer



























  • My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

    – Rajesh
    Mar 28 at 9:29











  • Will this returns true or false? And this will check all the indexes, right?

    – Anilkumar iOS ReactNative
    Mar 28 at 9:46












  • But, Its always returning false? even the values are 0

    – Anilkumar iOS ReactNative
    Mar 28 at 9:49












  • What is your definition of empty?

    – Ori Drori
    Mar 28 at 9:51






  • 1





    Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

    – Ori Drori
    Mar 28 at 9:55













3














3










3









Use Array.every() to check if all value keys are '0' (or whatever your definition of empty is):






const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)








share|improve this answer















Use Array.every() to check if all value keys are '0' (or whatever your definition of empty is):






const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)








const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)





const data = ["id":"508","class":"class1","value":"0","percentage":"8.90","color":"black","id":"509","class":"class2","value":"0","percentage":"2.40","color":"black","id":"510","class":"class3","value":"0","percentage":"56.40","color":"black","id":"511","class":"class","value":"0","percentage":"2.40","color":"black"]

const doEmptyAction = data.every(o => o.value === '0')

console.log(doEmptyAction)






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 9:19

























answered Mar 28 at 9:04









Ori DroriOri Drori

93.1k16 gold badges108 silver badges112 bronze badges




93.1k16 gold badges108 silver badges112 bronze badges















  • My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

    – Rajesh
    Mar 28 at 9:29











  • Will this returns true or false? And this will check all the indexes, right?

    – Anilkumar iOS ReactNative
    Mar 28 at 9:46












  • But, Its always returning false? even the values are 0

    – Anilkumar iOS ReactNative
    Mar 28 at 9:49












  • What is your definition of empty?

    – Ori Drori
    Mar 28 at 9:51






  • 1





    Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

    – Ori Drori
    Mar 28 at 9:55

















  • My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

    – Rajesh
    Mar 28 at 9:29











  • Will this returns true or false? And this will check all the indexes, right?

    – Anilkumar iOS ReactNative
    Mar 28 at 9:46












  • But, Its always returning false? even the values are 0

    – Anilkumar iOS ReactNative
    Mar 28 at 9:49












  • What is your definition of empty?

    – Ori Drori
    Mar 28 at 9:51






  • 1





    Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

    – Ori Drori
    Mar 28 at 9:55
















My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

– Rajesh
Mar 28 at 9:29





My suggestion would be to have callback as o => isEmpty(o.value) and have a custom isEmpty function which would look like isEmpty = (value) => value === undefined || value === null || value === ''. We can also check for empty objects/arrays in it. So OP has do define their empty criteria

– Rajesh
Mar 28 at 9:29













Will this returns true or false? And this will check all the indexes, right?

– Anilkumar iOS ReactNative
Mar 28 at 9:46






Will this returns true or false? And this will check all the indexes, right?

– Anilkumar iOS ReactNative
Mar 28 at 9:46














But, Its always returning false? even the values are 0

– Anilkumar iOS ReactNative
Mar 28 at 9:49






But, Its always returning false? even the values are 0

– Anilkumar iOS ReactNative
Mar 28 at 9:49














What is your definition of empty?

– Ori Drori
Mar 28 at 9:51





What is your definition of empty?

– Ori Drori
Mar 28 at 9:51




1




1





Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

– Ori Drori
Mar 28 at 9:55





Yes it will, but if it finds a non empty value, and will stop and return false. Ready the documentation of every in the link.

– Ori Drori
Mar 28 at 9:55













-1
















let arr = [

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

];

let desiredVal = arr.map((obj) =>
if(obj.value)
//do something

);





share|improve this answer




















  • 2





    Just a general suggestion, an answer is incomplete without explanation.

    – Rajesh
    Mar 28 at 9:30
















-1
















let arr = [

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

];

let desiredVal = arr.map((obj) =>
if(obj.value)
//do something

);





share|improve this answer




















  • 2





    Just a general suggestion, an answer is incomplete without explanation.

    – Rajesh
    Mar 28 at 9:30














-1














-1










-1









let arr = [

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

];

let desiredVal = arr.map((obj) =>
if(obj.value)
//do something

);





share|improve this answer













let arr = [

id: '508',
class: 'class1',
value: '0',
percentage: '8.90',
color: 'black'
,

id: '509',
class: 'class2',
value: '0',
percentage: '2.40',
color: 'black'
,

id: '510',
class: 'class3',
value: '0',
percentage: '56.40',
color: 'black'
,

id: '511',
class: 'class',
value: '0',
percentage: '2.40',
color: 'black'

];

let desiredVal = arr.map((obj) =>
if(obj.value)
//do something

);






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 9:17









Ankush RishiAnkush Rishi

1,0543 gold badges14 silver badges42 bronze badges




1,0543 gold badges14 silver badges42 bronze badges










  • 2





    Just a general suggestion, an answer is incomplete without explanation.

    – Rajesh
    Mar 28 at 9:30













  • 2





    Just a general suggestion, an answer is incomplete without explanation.

    – Rajesh
    Mar 28 at 9:30








2




2





Just a general suggestion, an answer is incomplete without explanation.

– Rajesh
Mar 28 at 9:30






Just a general suggestion, an answer is incomplete without explanation.

– Rajesh
Mar 28 at 9:30




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