Skip to content
Advertisement

Jquery – each get value, Find difference and convert to array

Used below HTML & JS code to get each value of base currency and member currency.

Need to get Memberprice value by finding a difference between base currency – member currency. Some times member-price will not exist. If condition to check and remove that base-currency from display. Then convert memberprice each value in array.

But, below code.. str1 & str2 outputs are coming as expected. But, memberprice difference get only first value. Not all.

Please help to guide and get a output in array format of extracted value like below based on example HTML shared.

[275, 258, 365, 348, 460] — 500 will be not there as there is no member-price div

JavaScript
JavaScript

Advertisement

Answer

You can loop through price-list div and get value from currency and base using find('.base-currency .price') same for other then subtract that values and add them inside arrays . Also , you need check if title already exist inside title array to avoid any duplicate.

Demo Code :

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement