JavaScript provides two different methods for iterating through arrays: `Object.keys(myarray).forEach` and `myarray.forEach((obj)

Is there a different method to iterate through my array of objects? The engine version on the application I'm using seems to be outdated and doesn't support myArray.forEach((obj) => {, but it works when dealing with single object arrays. Try using Object.keys(myArray).forEach().

{"jurisdiction":"SCPB - LON"},{"firstName":"David Dynamic"}

var array = []

$('input:checked').each(function() {

        var key_ = $(this).attr('name')
        var val = $(this).attr('name').val();

        var obj = {
            [key_]: val
        };
        array.push(obj);

        array.forEach((obj) => {
                    Object.keys(obj).forEach((key) => {
                            alert(key: " + key + " - value: " + obj[key]);
                            });
                    });
}); 

The error message from the webapp:

JST-310000 Error while compiling script '_webApp_APP303__preview' line 175: syntax error (line='     array.forEach((obj) => {
' token='> {
').
SCR-160032 JavaScript: error while compiling script '_webApp_APP303__preview'.

I also attempted another loop method without success.

array.forEach(obj => {
  
  for (let key in obj) {
    logInfo(`${key}: ${obj[key]}`);
  }

}); 

JST-310000 Error while compiling script '_webApp_APP303__preview' line 176: syntax error (line='array.forEach(obj => { ' token='> { '). SCR-160032 JavaScript: error while compiling script '_webApp_APP303__preview'.

Answer №1

The error message indicates that the Javascript engine in use does not support arrow function syntax, specifically encountering issues with the => token within the outer loop.

To resolve this issue, it is recommended to utilize only function callbacks:

    array.forEach(function (obj) {
        Object.keys(obj).forEach(function (key) {
            alert("key: " + key + " - value: " + obj[key]);
        });
    });

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

Creating a new bookmark in Firefox without encountering a pop-up dialog box

I am curious if it is feasible to utilize JavaScript to add a bookmark in Firefox seamlessly, without triggering any dialog box. Essentially, can I have the user click on a link and have the bookmark generated automatically, bypassing any additional step ...

Retrieving the data from an AJAX JSON variable

Inside my JavaScript function, I am fetching data like this: var jsonData = $.ajax({ url: "pie_chart_community.php", community_id: $c_id, dataType: "json", async: false }).responseText; Is there a way for me to access the community_id in ...

Update multiple rows in a MySQL database by using the values from an `$_

Struggling to update multiple rows in MySQL using an array from the $_POST variable named "units". Despite my efforts, I can't seem to crack this problem. Here is what I have attempted: My current code that doesn't update the 2nd person: if(iss ...

Issue with invoking Bracket-Shell bespoke Native (C++) Method

I'm currently working on developing a unique C++ function that can be invoked from JavaScript to resize the window. The necessary components are located in various files: Within appshell_extensions_platform.h: #if defined(OS_WIN) void ResizeWindow( ...

How to parse a JSON array into an array of maps in React with the help of Lodash

Consider the following JSON data structure with an array: { "status": { "time": 175 }, "hits": [ { "key1": "value1", "key2": "value2" }, { "key1": "value1", "key2": "value2" }, { "key1": "value1 ...

What is the most effective way to arrange an array in PHP by sorting it in descending order based

Can you help me with manipulating an array in PHP? $myval = array('name1'=>'google', 'name5'=>'yahoo', 'name3'=>'facebook','name2'=>'twitter','name4'=> ...

Struggling to get moment().utc() to display a two-digit format for the month and year

Currently, I am tackling a bug that has surfaced in a birthday component within my application. This component pulls the date of birth from its props in the format 1997-08-16T00:00:00Z. The challenge I am facing is that when the date of birth is set in the ...

A guide on embedding static content in the index.html page

During my project, I utilized vue-cli with webpack and encountered an issue when trying to load an image in index.html. Here is how it was done initially: <html> ... <style> .tag1 { background-image: url('<%= require(&ap ...

What is the best way to set a date input as required with AngularJS?

Angular 1.2.23 is the version I am currently using, and I want to set an input field with type=date as required. Here is the code snippet I have: <form name="form" novalidate> <input id="date" name="date" type="date" required /> <sp ...

Adjusting Bootstrap card content on hover

Currently, I am in the process of developing a website that features a list of products presented in bootstrap cards. I am seeking advice on how to dynamically change the text displayed on these cards when a user hovers over them. Specifically, I want to ...

When comparing strings, if they match, replace them with bold text

Today, I faced a challenging brain teaser that kept me occupied for over an hour. The task at hand is to compare two strings: the text input from the field and data-row-internalnumber. The goal is to determine if they match and then bold only the last let ...

Unable to load local import in JavaScript file

-projectName --Web Pages ---web.jsp --js When checking the console, I noticed the following: https://i.sstatic.net/vzOLr.jpg As for my import statement, the dataTables and other jQuery files were downloaded in the js folder. <script src="js/ ...

Trouble arises when attempting to transfer cookies between server in Fastify and application in Svelte Kit

In the process of developing a web application, I am utilizing Fastify for the backend server and Svelte Kit for the frontend. My current challenge lies in sending cookies from the server to the client effectively. Despite configuring Fastify with the @fas ...

Ways to invoke a function from a different JS file within a Mountebank response block

I need help with decorating the response of a mountebank. I am struggling to call a function from another js file within the response code block. Can anyone provide some guidance? The javascript file in question is: utils.js function getRandomCharAndNum( ...

Controlling Formatting in ASP.NET

Feeling puzzled by a seemingly simple question with no clear solution in sight. We're attempting to transition an interface to an ASP.NET control that currently appears like this: <link rel=""stylesheet"" type=""text/css"" href=""/Layout/CaptchaLa ...

Transitioning from using static data sets for cascading dropdowns in Angular 4 to fetching a dynamic object from a web API request

When starting a new project involving .net core and Angular 4, I had to wait for the implementation of a real database. Now that the database is in place, a DBA and backend developer have created a web api from which I need to retrieve a nested object con ...

What is the most efficient way to calculate the current percentage of time that has elapsed today

Is there a way to calculate the current time elapsed percentage of today's time using either JavaScript or PHP? Any tips on how to achieve this? ...

Iterate through an array of objects and add them to a fresh array

I am encountering an issue where I would like to generate a fresh array of objects in order to avoid utilizing a nested array map. However, the error message below is being displayed: TypeError: Cannot read property 'subscriber_data' of undefine ...

Replace the empty slots in the array with an underscore

Is it possible to use underscorejs to populate missing elements in an array? For example: fillGaps([1,2,3,6,7,22,23,24]) => [1,2,3,'...',6,7,'...',22,23,24] ...

"What could be causing the jQuery to not function properly in the head section

After experiencing slow loading times for the navigation menu on mobile devices, I decided to move my code to the <head> area. You can check out the demo at this link: I'm utilizing TinyNav.js to convert my navigation into a select dropdown. In ...