Mollie Posted August 2, 2021 Report Share Posted August 2, 2021 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. Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted August 2, 2021 Report Share Posted August 2, 2021 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 Mollie 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.