Link to home
Start Free TrialLog in
Avatar of gautam_reddyc

asked on

How to avoid undefined index in Javascript

Hello, I am trying to load an array with client side actions, but in the process there are a few unnecessary fields loading in. They have a blank id and a value of undefined. How can i avoid these undefined values to load into my array.

When I tried to get them by using a conditional if loop where the value == 'undefined', they still load into the array. Is there a remedy for this. There are a lot of these, so using this array has been a problem.
Avatar of andrux
Flag of Mexico image

Can you provide your code?
Avatar of leakim971
Flag of Guadeloupe image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if the value is null then test for: value == null

if it is undefined then test for: value == undefined

you can even do a strict equality (===) but I'm not sure that's necessary. fyi - don't enclose null or undefined in quotes! :)
Thanks a lot for the points! Have a nice week-end!