Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

How to compare two arrays in jquery

$
0
0

I want to compare two arrays and if they are equal, add a new attribute to html.

First my html

<ul class="checkout__delivery-collect-shoplist" data-bind="foreach: currentOptions ">
  <li class="checkout__delivery-collect-shop js-delivery-item active">
    <h6><em data-bind="text: label">Name1</em></h6>
  </li>
  <li class="checkout__delivery-collect-shop js-delivery-item">
    <h6><em data-bind="text: label">Name2</em></h6>
  </li>
</ul>

First I am creating new array with text

var arr = [];
jQuery('em[data-bind="text: label"]').each(function() {
    arr.push(jQuery(this).text().split(';'));
});

Also, I have another array with text

var Managerss = Manager.GlobalData[2].options
Managerss.filter(x => x.payment_checkmo === '1').map(x => x.label);

It will give

["Name1", "Name2"]
0: "Name1"
1: "Name2"
length: 2
__proto__: Array(0)

So I first need to compare these arrays and if this true create new attribute data-payment = '0' to li.class checkout__delivery-collect-shop js-delivery-item

Example what I want

<ul class="checkout__delivery-collect-shoplist" data-bind="foreach: currentOptions ">
  <li class="checkout__delivery-collect-shop js-delivery-item active" data-payment='0'>
    <h6><em data-bind="text: label">Name1</em></h6>
  </li>
  <li class="checkout__delivery-collect-shop js-delivery-item" data-payment='0'>
    <h6><em data-bind="text: label">Name2</em></h6>
  </li>
</ul>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>