Would anyone know how to loop through all ID's that being with name_
So, for example, within the markup I may have 50 id's that all start with "name_", the full ID would be like name_2, name_55, name_25, etc.
I'd like to loop through all of these getting the number.
Not really sure where to begin....... thank you!
Object. key(). It returns the values of all properties in the object as an array. You can then loop through the values array by using any of the array looping methods.
The Object. keys() method was introduced in ES6. It takes the object that you want to iterate over as an argument and returns an array containing all properties names (or keys). You can then use any of the array looping methods, such as forEach(), to iterate through the array and retrieve the value of each property.
use the attribute starts with selector
$('[id^=name_]').each(function() {
var number = this.id.split('_').pop();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With