Determine the status of elements in two arrays after they have been re-ordered based on their

In my interactive quiz, arr1 can be rearranged via drag and drop while arr2 represents the correct array order.

The goal is to compare the reordered indexes of arr1 with the ids in arr2 by using the re-ordered index of value1.

For example, currently items 0 and 4 in arr1 should be considered correct after comparison.

I attempted a comparison using: if (value1.image === value2.image && value1.$index=== value2.id)

Unfortunately, this approach did not work as expected.

Check out the quiz here

Answer №1

It's important to make a comparison between the index and the id in this case. Keep in mind that the index is an integer, while the id within your array is a string that needs to be parsed for accurate checking.

Below is the code snippet:

angular.forEach(list1, function(item1, index1) {
    angular.forEach(list2, function(item2, index2) {
        if (item1.image == item2.image && index1 == parseInt(item2.id)) {
            console.log(item2.status);
        }
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on configuring browser compatibility for a NetBeans JSP application

While developing a JSP web application, I encountered an issue with certain buttons and labels not being visible in Internet Explorer but working fine in Google Chrome. How can I ensure that my application is compatible with all browsers for optimal user ...

How to target a single TypeScript file in a React project that does not use TypeScript for compilation

I created a ReactJS application using the following command: $ npx create-react-app react-app-vanilla This app includes the following files: /.gitignore /README.md /package.json /public/favicon.ico /public/index.html /public/logo192.png /public/logo512.pn ...

What is the solution to the error message "TypeError: Cannot read property 'firstname' of undefined" when working with Firebase and Cloud Functions?

I'm having some trouble creating a new Document in my Firestore database using Cloud Functions. I am also using Postman to send a POST request with the following data: { "firstname": "TestFirst2", "lastname": "TestLast2", "email": "< ...

What is the best way to retrieve the http.server object from the express application?

Currently, I am in the process of developing a server-side node.js application utilizing express to manage HTTP requests. In addition to this, I am incorporating websockets (socket.io) support into the application. The challenge I face is that I do not hav ...

Cutting an image in ReactJS using the HTML5 canvas feature

Seeking a way to crop images in reactjs without relying on any external library. The goal is for users to upload an image and perform cropping using raw JavaScript, then replace the uploaded image. How can this be achieved without the use of libraries? Loo ...

Is there a way to identify all rows that have been styled using CSS in JS?

I am looking to identify the rows that have been selected through CSS using Javascript. I have attempted some approaches with code snippets gathered from various sources. Here is an example below: ... var tableRows = document.getElementsByTagName('tr ...

Guide on adding a timestamp in an express js application

I attempted to add timestamps to all my requests by using morgan. Here is how I included it: if (process.env.NODE_ENV === 'development') { // Enable logger (morgan) app.use(morgan('common')); } After implementing this, the o ...

Is it possible to selectively add Bootstrap classes to certain sections of a pre-existing website without changing the current styling in place?

What is the best way to customize Bootstrap classes for specific blocks or modify default classes, like changing .row to .row_2, without impacting other elements styled with different Bootstrap classes? ...

What is the best way to insert hyperlinks within every cell of a table using Angular?

I am currently working on a table created with ng-repeat in Angular. The cells are populated by variables in the scope. <tbody> <tr ng-repeat="item in items" myDirective> <td>{{item.title}}</td> <td>{{item.field}}&l ...

Encountered an eas error during Android build process

When I try to execute the command "eas build --platform android" I encounter the following error message: "✖ Build failed ...

JavaScript barcode data input

I am working with 2 inputs - #barcode and #quantity. When using a barcode scanner, I can easily enter the quantity after scanning data by pressing the Tab key. Typically, the quantity is null, indicating one piece. Currently, my cursor is in the #quantity ...

Issue with integrating e-junkie shopping cart with Bootstrap 5

After transitioning from Bootstrap 4 to Bootstrap 5 and encountering navigation issues on smaller screens, I delved into the code to uncover the source of the problem. It turns out that the collapse button in the navbar wasn't functional due to confli ...

Problem encountered in Python with Selenium/WebDriver: Unable to convert script into a string

I am still a beginner with selenium and I'm trying to figure out how to run a javascript function using python and then utilize the value that it returns. I've encountered an error that has me stuck. Any assistance would be greatly appreciated. H ...

Grabbing a specific section of a URL in AngularJS: Tips and Tricks

I have a URL that appears as: www.ccadmin/admin.jsp?id=Aetna834 Is there a way to extract the value Aetna834 from it? ...

What is the proper way for AJAX to function in WordPress when there is no output function available?

I am looking to incorporate AJAX functionality into my WordPress site to make a call to a third-party API. The goal is to update the state of some checkboxes based on the response received. While I have experience with AJAX, my previous implementations in ...

Retrieve information for AJAX tooltip from a specific URL

I am currently utilizing a script for tooltips. Is there a method available to dynamically load the content of a tooltip from a URL (using dynamic content loaded from a PHP script) rather than specifying the path to an html/php file? For Example What I ...

Can you explain the distinctions between using this['key'] and $data['key'] in the context of v-model?

Take a look at the snippet below, which includes three demos. The first two demos are functioning correctly (v-model is working fine). However, in the last demo, when you type something into the <input>, you will notice that this['test 1'] ...

Guide to integrating external Vue npm components into your project

After diving into Vue.js, I am now incorporating it into an existing project without the option of using .vue files. This is a standalone setup not utilizing webpack, which requires the files to be stored locally for functionality. In my current scenario, ...

The useEffect hook in ReactJs is triggering multiple times

Encountering challenges while developing an Infinite scroll using ReactJs and Intersection observer API. Upon initial application load, the API gets called twice instead of once. This behavior may be due to strict mode, although not confirmed. Additionall ...

Determining the appropriate width based on the length and style of text

Imagine you possess <span class='class'>gfdsdfgfdsg</span> Is there a way to determine the exact size in pixels that I need for it before rendering? (I'm not looking for automatic adjustment, just a calculation.) ...