The final piece left in stitching together an array

Issue I have been struggling with this code for some time now and I can't seem to figure out the solution. I am receiving 3 values from inputs and trying to remove all the empty spaces "" in the array, but when I execute the code, it displays the following:

["mm", "111", "100"]
["inches", "222", "95"]
["phi", "33", "55"]
[""]  // <---- **Need help removing this** 

JavaScript Code

$(document).ready(function() {
  $('#sub').click(function() {
    var my_arr = [];
    var split;
    $('td').each(function() {
      my_arr.push($(this).children().val());
      for (var e = my_arr.length - 1; e--;) {
        if (my_arr[e] === "") my_arr.splice(e, 1);


        var i, j, chunk = 3;
        for (i = 0, j = my_arr.length; i < j; i += chunk) {
          split = my_arr.slice(i, i + chunk);
          console.log(split);
        }
      }
    })
  })
})

HTML Structure

<div class="top-content">
        <div class="inner-bg">
            <div class="container">
                <div class="row">
                    <!--    Header Text     -->
                    <div class="col-sm-10 text">
                        <h1><strong>SAGA</strong> Data Form</h1>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-6 form-box">
                        <div class="form-top">
                            <div class="form-top-left">
                                <h3>Enter Data Below</h3>
                                <p>Please Enter Data to be converted</p>
                            </div>
                            <div class="form-top-right">
                                <i class="fa fa-rocket"></i>
                            </div>
                        </div>
                        <div class="form-bottom">
                            <form action="" class="login-form" method="post" role="form">
                                <div class="form-group">
                                    <form id="add_name" name="add_name">
                                        <div class="table-responsive">
                                            <table align="center" class="table table-bordered" id="dataTable">
                                                <!--    Form Titles     -->
                                                <tr>
                                                    <th>Select</th>
                                                    <th>Text1</th>
                                                    <th>Text2</th>
                                                    <th></th><!--    Form Elements       -->
                                                </tr>
                                                <tr>
                                                    <td><select class="unit selectpicker show-tick form-control" data-live-search="true" id="basic">
                                                        <option value="mm">
                                                            Millimeters
                                                        </option>
                                                        <option value="micron">
                                                            Micron
                                                        </option>
                                                        <option value="phi">
                                                            Phi
                                                        </option>
                                                        <option value="inches">
                                                            Inches
                                                        </option>
                                                        <option value="Mesh">
                                                            Mesh
                                                        </option>
                                                    </select></td>
                                                    <td><input class="form-control name_list" id="unitVal" name="name[]" placeholder="Enter Unit Here" type="text" value="75000"></td>
                                                    <td><input class="form-control name_list" id="percent" name="name[]" placeholder="Enter Percent Finer Here" type="text"></td>
                                                    <td><button class="btn btn-success" id="add" name="add" type="button">Add More</button></td>
                                                </tr>
                                            </table>
                                        </div><!-- Place BTN here to submitt form          -->
                                    </form>
                                </div><button class="btn" id="sub" type="submit">Submit</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Answer №1

Consider removing a specific element from the array

  let value = $(this).children().val();
  if (value !== "") {
    my_array.push(value); 
  }

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

The p5.play library does not function properly on repl.it

I've recently started using p5.play, but I keep encountering this error whenever I try to run a program (I'm using repl.it); p5 is having issues creating the global function "Animation", possibly because your code already uses that name as a va ...

Disable automatic playback of HTML video

There is an HTML video with an image that loads initially and then disappears to play the video. I would like the image to always be visible until I click on it. Once clicked, the video should start playing. You can view the code on JSFiddle: http://jsf ...

State of loading getServerSideProps in Next.js

Can we implement a loading state similar to when retrieving data on the client-side? I'm interested in having a loading state, maybe with a loading-skeleton like react-loading-skeleton On the client-side, we can achieve this by: import useSWR from & ...

Tips for preserving user input from HTML into a text file and then reloading it back into the HTML document

I have recently created a character sheet for a game using HTML. The HTML file is mainly comprised of various input tags such as <input type="text">, <input type="number">, <input type="checkbox">, <input type="radio">, <select&g ...

What is the proper way to use an AND operation in jQuery on multiple attributes?

I have a list of DIV tags structured as follows: <div status="1" searchText="some text">...</div> <div status="2" searchText="more text">...</div> <div status="1" searchText="even">...</div> To toggle the visibility of ...

Accessing Public Photos from Facebook Users

Is it possible to create a web app that can retrieve all public photos from any user's Facebook account using their profile URL? For instance, some Facebook profiles allow non-logged in users to view profile pictures and cover photos. I am developing ...

<use> - SVG: Circles with different stroke properties

Why is the stroke of both <use> elements being ignored here? The stroke color of <circle> is set to blue, which is also appearing on both <use> elements. Why? I am trying to set different stroke colors for all three of these elements, bu ...

Analyzing the attributes of an array object in JavaScript

I have an assignment that requires me to filter an array into a new array for a vehicle with the term "ford" in it. The format should be in ES6 using arrow function syntax, like this: const arr = [ {name: "Honda", type: "Accord"}, {name: "ford", type: "fu ...

Guide on sending several HTTP requests from a Node.js server with a shared callback function

Is there a way to efficiently make multiple HTTP calls in a Node.js server with a shared callback function? Are there any modules or libraries that can help with this? ...

Calculate the total of each row in an array with multiple dimensions

I am trying to calculate the sum of each row in a multidimensional array: $number = array ( array(0.3,0.67, 0.3), array(0.3,0.5,1), array(0.67,0.67,0.3), array(1,0.3,0.5) ); The desired result should be as follows: row1 = 1.27 row2 = 1.8 ...

Error: The XPath expression provided is invalid for use with the scrollIntoView function in Selenium

My task involves utilizing Python to extract data from a website that features a filter pane requiring scrolling. I came across a code snippet that aids in navigating through a list of elements by iterating through a loop. recentList = driver.find_element ...

Javascript functions function properly only if they contain the 'alert()' command

My aim is to utilize Ajax (Javascript + php) for checking user name availability when a user moves focus to another form field. The strange part is that my functions only work when I include some alert(), without them, the functions fail to operate. Anoth ...

Having trouble making JSON work alongside Ajax and jQuery?

In my JavaScript, I have the following code snippet... $.ajax({ type: 'POST', url: 'http://www.example.com/ajax', data: {email: val}, success: function(response) { alert(response); } }); The PHP fil ...

Caution: the index of the array is outside the boundaries of the array [-Warray-bounds] within the

static int myarray[2]={-1,234}; module_param_array(myarray,int,&arrayargc,0); MODULE_PARM_DESC(myarray,"Integer Array"); static int __init module_init_2(void) { int i; for(i=0;i< (sizeof myarray/sizeof(int));i++); { printk(KERN_INFO "mya ...

Trouble presenting information retrieved from API

I'm encountering an issue with displaying the data I fetched from an API. I'm not sure what's causing the problem... I attempted to use the map() function to access the data, but it's not functioning as expected either. import React fr ...

Which Browser (or version) is the Only One That Cannot Manipulate Flash Objects?

In my attempts to modify Flash Objects / Embeds using Javascript, I've found that it works in all browsers except for IE. This has led me to consider abandoning IE altogether for this application, unless there are other older or less used browsers tha ...

Learn how to access the `$root` instance in Vue.js 3 setup() function

When working with Vue 2, accessing this.$root is possible within the created hook. However, in Vue 3, the functionality that would normally be placed within the created hook is now handled by setup(). The challenge arises when trying to access properties ...

Using an AJAX function to retrieve data from two different server-side scripts and populate two separate HTML elements on the page

My goal in this coding situation is to change values in multiple DOM targets. The example from Tizag shows the DOM being altered within the onreadystatechange function, like this: if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequ ...

Having trouble with AngularJS and NodeJS routing integration?

After deciding to dive into the world of application development using the MEAN Stack, I encountered a major roadblock. For the past hour, I've been struggling to set up a basic route, only to face failure at every turn. Whenever I try to access my ...

An error was encountered: "Uncaught SyntaxError: Unable to utilize import statement outside of a module in

I have come across the following code while learning React and trying to execute it. HTML <html> <head> <link href="index.css" rel="stylesheet"> </head> <body> <div id="r ...