Jump to content

Working with arrays in JavaScript


Recommended Posts

Hi;
I have an array and I want to do an operation on it. Let me explain with an example:
Suppose we have the following array (the length of the array may be any number)
[1,2,3,4]
If I select any of the array cells, I want the subsequent cells to be removed from the array.
For example, if cell 3 is selected, cell 4 is removed from the array, or if cell 2 is selected, cells 3 and 4 are deleted.
Thank you for your help.

Link to comment
Share on other sites

3 hours ago, Mollie said:

Hi;
I have an array and I want to do an operation on it. Let me explain with an example:
Suppose we have the following array (the length of the array may be any number)
[1,2,3,4]
If I select any of the array cells, I want the subsequent cells to be removed from the array.
For example, if cell 3 is selected, cell 4 is removed from the array, or if cell 2 is selected, cells 3 and 4 are deleted.
Thank you for your help.

What's your goal here?

I have the following

<script>
document.addEventListener("DataPageReady", function arrays(){

var arr = [1,2,3,4];

var arrblnk=[];

var val = 2;

var position = arr.indexOf(val);

for (i=0; i <= position;  i++){

arrblnk.push(arr[i]);

}

});

</script>

the array - arr

A blank array - arrblnk

the value in the array - val

position of that value in the array - position

for loop will go through each value until the position, and then 'push' insert the values in the blank array up until the said value

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...