Dee J. Dee J. - 1 year ago 86
AngularJS Question

How to remove an array element using a specific value

Suppose I have an array structured like this:

{ q1: true, q2: false, q3: false, q4: true, q5:true }

Is there a way to remove all the elements that has "false" for a value in AngularJS?

I tried using splice() by getting the index number, with no luck. Now I'm looking for a way where I don't have to use a specific index number.

Any help would be appreciated. Thank you.

Answer Source

Simple JavaScript approach

var r = {
  q1: true,
  q2: false,
  q3: false,
  q4: true,
  q5: true

for (a in r) {
  if (!r[a]) {
    delete r[a]


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download