Why does Internet Explorer keep throwing the error message "expected ')' while Firefox is not affected?

When running this code, Internet Explorer throws an error ')' is expected while Firefox executes it smoothly. The console in Internet Explorer points to the first line:

function HTMLtableRows (titles=[] , values=[]) {

How can I resolve this issue?

function HTMLtableRows (titles=[] , values=[]) {

            var i, j;
            var str, strT, strM;
            str = '<table class="table">';

            str = str + '<tr>';
            for (j = 0; j < titles.length; j++) {
                str = str + '<th colspan="2"><center>' + titles[j] + '</center></th>';
            }
            str = str + '</tr>' + '<tr>';
            for (j = 0; j < titles.length; j++) {
                str = str + '<th>Tijdstip</th>' + '<th>Looptijd</th>';
            }
            str = str + '</tr>' + '<tr>';
            for (j = 0; j < titles.length; j++) {
                var a = values[j].split('\r');
                strT = ''
                strM = ''
                for (i = 0; i < a.length; i++) {
                    var b = a[i].split('=');
                    if (b[1] != undefined) {
                        strT = strT + b[0];
                        strM = strM + b[1] + 'min';
                    }
                    if (i < a.length - 1) {
                        strT = strT + '<br>';
                        strM = strM + '<br>';
                    }
                }
                str = str + '<td>' + strT + '</td>';
                str = str + '<td>' + strM + '</td>';
            }
            str = str + '</tr>';

            str = str + '</table>';

            return str;

        }

Answer №1

Internet Explorer does not support default parameters.

One way to work around this is by following this approach

function HTMLtableRows (titles , values) {
  if (!titles) titles = []; 
  if (!values) values = [];
  
  console.log(titles);
  console.log(values);
}

a1 = [1,2,3];

HTMLtableRows(a1, null);
HTMLtableRows({foo: "bar"}, undefined);
HTMLtableRows(2, NaN);
HTMLtableRows("not empty string", "");
HTMLtableRows(1, 0);
HTMLtableRows(true, false);

All the mentioned values

  • null
  • undefined
  • NaN
  • ""
  • 0
  • false

will be converted into an empty array. If you want certain values to not be replaced with an empty array, modify the if conditions accordingly.

For instance, where you keep values as "", 0, and NaN unchanged:

function HTMLtableRows (titles , values) {

  if (!titles) titles = []; 
  if(values != "" && 
     values != 0  && 
     !isNaN(parseInt(values))
    )
    values = [];
  
  console.log(titles);
  console.log(values);
}

HTMLtableRows("string", "");
HTMLtableRows(1, 0);
HTMLtableRows(7, NaN);

Answer №2

Special thanks to Alex for helping me find the solution through the modifications provided:

function updateTableData (newTitles , newValues) {
  titlesArray=[]; 
  valuesArray=[];
  titlesArray = newTitles;
  valuesArray = newValues;
  //...
}

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

Obtaining information from a database and integrating it into introjs utilizing JSON

Currently, I am using IntroJs and JSON to call the introjs. I am wondering if it is possible to store data/text/info in a database and then retrieve it using JSON? <h2 id="welcomeMsg">Welcome back,<asp:Label ID="lbl_WelcomeName" runat="server" Te ...

What are the steps to implement IndexedDB in an Angular application?

I'm searching for a solution to utilize indexedDB within Angular. I need assistance with implementing data recovery or potentially using a browser-based database that doesn't have the 5 MB limit like localStorage. Can anyone point me in the right ...

Merge two arrays of objects together and eliminate duplicates based on a specific attribute

I am currently working with two arrays of objects. One array retrieves data from an API to display in the application, while the other array fetches data from localStorage, which includes modifications made to the original data stored in the first array. M ...

Add a string to the beginning of the JSON data before displaying it

Upon receiving JSON data through an AJAX call, the format of the data is structured as follows: data[0].scores.sadness The term 'sadness' in the above example represents one of the eight emotions. Instead of printing out individual emotions lik ...

Issue: ngModel: Unassignable Value

I am currently working on a piece of code that dynamically generates a drop-down list. My goal is to set the selected value using ng-repeat. In order to achieve this, I have implemented a function in ng-model. However, I am encountering an issue with the f ...

Having trouble establishing a connection between a Javascript client and a PHP server using websockets

My current setup involves a PHP server that receives "messages" from remote PHP clients. Upon receiving a message, the server should update a GUI using Javascript web sockets on localhost. Although the PHP server is successfully receiving messages, I am en ...

Mastering AJAX with Django

I'm currently struggling to understand how to create an AJAX function, as all the tutorials I've come across seem too complicated for me. This is my HTML code: <a href="{% url pay_provider id=statement.statement_id %}" id="pay_provider">P ...

Having trouble uploading files with jQuery File Upload functionality

Issue: I need to set a session variable and redirect the user to a different PHP page after uploading a .txt file using jQuery File Upload. HTML code (upload.php): <!-- The fileinput-button span is used to style the file input field as button --> ...

Issue with MSBuild in DevOps - Unable to Locate NuGet Package

After creating a DevOps Pipeline to build an asp.net website, I encountered an error when using Pipelines: Error CS0246: The type or namespace name 'Azure' could not be found (are you missing a using directive or an assembly reference? Despite i ...

Avoid working on the script for the element in the partial view during the event

In my index.cshtml view, I have a script that triggers an AJAX call when the SearchingManagerId2 element is changed. $("#SearchingManagerId2").on("change", function () { var valueForSearch = $(this).val(); $.ajax({ ...

Disable the height property in the DOM when implementing the jQueryUI resizable feature

I'm utilizing the flex property to create a responsive layout for my web application. In order to enable resizing of my navigator panel, I have implemented jQuery UI. However, upon triggering the resize event, jQuery UI is adding a hardcoded height t ...

Tips for setting up nested folders using Node.js on a Windows machine:

Is there a way to use Nodejs in Windows 10/11 to create a parent folder and then add a new folder inside of that parent folder, like this: parent/child within the Documents folder? ...

What is the best way to utilize both the YouTube API and jQuery in order to successfully transfer a video file

I am currently working on utilizing the Youtube DataAPI in order to upload a video to our website's YouTube account. Although I have been referring to the documentation for Browser-based uploading and following its provided examples, I am facing troub ...

Conceal content upon initial page load, then unveil after a set period of time

Is there a way to hide a paragraph on page load and reveal it after a certain amount of time has passed? I assume JavaScript will be needed, but I'm not sure where to begin. Any suggestions? ...

What's the best way to ensure that only the most recent 100 entries are retained in a CSV file

Currently, I am working on an application that requires me to extract timestamp-based parameter values from various devices. The data is highly structured and because I have to retrieve 100k rows every few minutes, I haven't explored the option of usi ...

The collection is not an array

I am currently running the following code: var n = []; jQuery.toJSON( n ); Interestingly, on one page I receive "[]", while on another I get ""[]"". Both pages are utilizing the same version of jQuery along with a toJson Plugin. Upon inspecting the arra ...

The SourceMap in DevTools encountered a parsing error with the message: "chrome-extension

It's been about a week since I first noticed warning messages appearing in my Google Chrome console. https://i.sstatic.net/Aurgz.png Clearing the cache hasn't made a difference; the messages only vanish when in incognito mode. Any suggestio ...

.sort method will produce a map with just one element

I have a map that contains 10 entries displayed in the first 10 lines of the "logs" section below. The map is populated with values in the following manner: const featuresMap = {}; for (const feature of features) { featuresMap[feature.getName()] = feat ...

Creating fresh paths in ReactJS

Is it possible to implement new routes in react JS with the current code provided below? I am looking for a way to create a route that does not need authentication. ReactDOM.render( <Provider store={store}> <PersistGate loading={null} ...

Unable to expand the width of the video element

So I have encountered a situation like this The video displayed does not fully expand to the width of its containing element. This is what my HTML structure looks like - <div class="webcam"/> <div class="control-container"> </div> ...