Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

formatting
Source Link
Pabs123
  • 3.4k
  • 15
  • 30

I have an array of Objects in JavaScript and I'm having trouble accessing JS methods on my array.

Is there a way to use methods such as removeClass or attr on an array without having to use a for loop? For example, in jQuery if I do $("li.listing").removeClass("listing")....it will remove the listing class from all li tags where this class is present.

Is there a way without having to use multiple for loops, to use these methods on an array (so that it looks at each element/object in the array)?

Example

cars.removeClass("listing") // Remove listing class from every element in cars array - is this syntax or something similar possible? Thanks!

Array index [0] example

0: m.fn.init [li#listing-MCMR-R-ZT-BFNT001-ZT-BFNT001.listing.filtered-out-by-car-type.listing-filtered-out, prevObject: m.fn.init(1), context: car, selector: "li.listing"]

0: m.fn.init [
 li#listing-MCMR-R-ZT-BFNT001-ZT-BFNT001.listing.filtered-out-by-car-type.listing-filtered-out, 
 prevObject: m.fn.init(1), 
 context: car, 
 selector: "li.listing"
]

I have an array of Objects in JavaScript and I'm having trouble accessing JS methods on my array.

Is there a way to use methods such as removeClass or attr on an array without having to use a for loop? For example, in jQuery if I do $("li.listing").removeClass("listing")....it will remove the listing class from all li tags where this class is present.

Is there a way without having to use multiple for loops, to use these methods on an array (so that it looks at each element/object in the array)?

Example

cars.removeClass("listing") // Remove listing class from every element in cars array - is this syntax or something similar possible? Thanks!

Array index [0] example

0: m.fn.init [li#listing-MCMR-R-ZT-BFNT001-ZT-BFNT001.listing.filtered-out-by-car-type.listing-filtered-out, prevObject: m.fn.init(1), context: car, selector: "li.listing"]

I have an array of Objects in JavaScript and I'm having trouble accessing JS methods on my array.

Is there a way to use methods such as removeClass or attr on an array without having to use a for loop? For example, in jQuery if I do $("li.listing").removeClass("listing")....it will remove the listing class from all li tags where this class is present.

Is there a way without having to use multiple for loops, to use these methods on an array (so that it looks at each element/object in the array)?

Example

cars.removeClass("listing") // Remove listing class from every element in cars array - is this syntax or something similar possible? Thanks!

Array index [0] example

0: m.fn.init [
 li#listing-MCMR-R-ZT-BFNT001-ZT-BFNT001.listing.filtered-out-by-car-type.listing-filtered-out, 
 prevObject: m.fn.init(1), 
 context: car, 
 selector: "li.listing"
]
Source Link
Michael
  • 443
  • 1
  • 11
  • 32

Using JavaScript/jQuery methods on array of objects?

I have an array of Objects in JavaScript and I'm having trouble accessing JS methods on my array.

Is there a way to use methods such as removeClass or attr on an array without having to use a for loop? For example, in jQuery if I do $("li.listing").removeClass("listing")....it will remove the listing class from all li tags where this class is present.

Is there a way without having to use multiple for loops, to use these methods on an array (so that it looks at each element/object in the array)?

Example

cars.removeClass("listing") // Remove listing class from every element in cars array - is this syntax or something similar possible? Thanks!

Array index [0] example

0: m.fn.init [li#listing-MCMR-R-ZT-BFNT001-ZT-BFNT001.listing.filtered-out-by-car-type.listing-filtered-out, prevObject: m.fn.init(1), context: car, selector: "li.listing"]

lang-js

AltStyle によって変換されたページ (->オリジナル) /