Questions tagged [splice]

splice copies data between two file descriptors of which one must be a pipe. Effectively, this is equivalent to a userland function that performs a read/write operation to and from a kernel-owned buffer.

splice copies data between two file descriptors of which one must be a pipe. Effectively, this is equivalent to a userland function that performs a read/write operation to and from a kernel-owned buffer.

The splice system call can be used to implement , as described in Zero-Copy in Linux with sendfile() and splice().

738 questions
4
votes
5 answers

How to remove the next element after the first?

The goal was to get every other element of an array that matches the condition I had, but I couldn't get to do that. So, I set off to try on another example which is found in the Array.prototype.indexOf() at MDN. var beasts = ['ant', 'bison',…
4
votes
2 answers

Function render after splice and setState()

I want my React function to re-render after I splice an array. Here Is (part of) the function (using Hooks): function showProblem() { const [andArray, setAndArray] = useState([]); const deleteTag = (i, arr) => { let and = andArray; switch…
Fabio Russo
  • 271
  • 1
  • 3
  • 13
4
votes
5 answers

Can't remove all Boolean == false in array

Given an array with different data types. I write a function to find those values which are false and return the array without the falsy values. For example: [7, "ate", "", false, 9] should return [7, "ate", 9]. This is my current code: function…
S.H
  • 671
  • 2
  • 6
  • 22
4
votes
2 answers

Array object gets removed from list before splice() statement (JS)

DISCLAIMER: This is part of a lab assignment for school Update: I want to keep this for reference in the future, so I will just delete the code portion. Thanks to everyone who helped! You were a big help Assignment (Sum of it): Create a celebrity…
Berman
  • 47
  • 4
4
votes
6 answers

splice not removing element from array

I am using splice to remove an element from an array, but it's not working. as far as I know, the code looks okay , but maybe I am missing/overseeing something. please take a look. here 'state' is an array containing objects. let removeFromState =…
faraz
  • 2,603
  • 12
  • 39
  • 61
4
votes
3 answers

Vue array.splice removing wrong item from list

I have a list and I am using a for loop to loop through it. The structure looks like this: salesLists: { 1: [ [], [], [] ] 2: [ [], [] ] } And html:
senty
  • 12,385
  • 28
  • 130
  • 260
4
votes
1 answer

Why can't I remove item from this Array using slice or lodash remove?

Using slice (In this situation I find the correct item in the Array, attempt slice, but the Array stays exactly the same): for (var i=0; i
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
4
votes
2 answers

Javascript - remove specific element from dynamically created array

I have a page where users can create tags (much like here in stackoverflow), which are then sent(POST) to the back end to be stored in a database. The user can make tags but also remove them before finally hitting Submit. In the DOM the tags are…
bjurtown
  • 163
  • 4
  • 13
4
votes
3 answers

Calling splice inside map function

I have following code: var a = [{a: 1}, {a: 2}, {a: 3}]; a.map(function (item, index) { console.log('call'); if (index < 1) { a.splice(index, 1); } }); But call is printed only two times, and I expect to be printed three times. I know…
user232343
  • 2,008
  • 5
  • 22
  • 34
4
votes
1 answer

Why does splice not fill the holes on a javascript array?

Suppose that you run this code: var a = []; a[4] = true; Then your array would look like [undefined, undefined, undefined, undefined, true] But if you run this code: var a = []; a.splice(4, 0, true); You would get [true] instead of, well,…
Ale Morales
  • 2,728
  • 4
  • 29
  • 42
4
votes
3 answers

Javascript Array Splice Not working fine

var cache = []; cache[0] = "0"; cache[1] = "1"; cache[2] = "2"; cache[3] = "3"; cache[4] = "4"; cache["r"] = "r"; console.log(cache.length); for(key in cache){ if(isNaN(key))continue; else cache.splice(key,1); // cache.splice(key) is working…
Wasim A.
  • 9,660
  • 22
  • 90
  • 120
4
votes
1 answer

forward_list::splice_after( const_iterator pos, forward_list& other, const_iterator i ) functionality

I'm reading different interpretations of the way this function should work. cplusplus.com says that this function should "move the element directly AFTER i". Yet cppreference.com says that it splices the element AT i. MSvisual studio agrees with…
paul23
  • 8,799
  • 12
  • 66
  • 149
4
votes
4 answers

Why splice() method changes the value of other array?

I have an array say var list = ["first", "second"]; now I assign list to some other variable say var temp = list; Now when I use splice on list like list.splice(0,1); Now when I check the value of list it shows list = ["second"] Also when I…
me_digvijay
  • 5,374
  • 9
  • 46
  • 83
3
votes
2 answers

Understanding result returned from splice in CoffeeScript

I am using CoffeeScript along with the JS splice function. My understanding of the JS splice function is that it should return the objects that were spliced out and modify the original array. This seems to work ok with simple arrays but when I…
Alexis
  • 23,545
  • 19
  • 104
  • 143
3
votes
2 answers

Common Lisp: How to build a list in a macro with conditional splicing?

Let's assume: (defmacro testing (&optional var) `(list 'this 'is ,@(when (consp var) `('a 'list)))) when called: >(testing 2) (THIS IS) >(testing (list 1 2)) (THIS IS A LIST) which is what I wanted. But now, when I pass a parameter…
mck
  • 1,334
  • 2
  • 12
  • 20
1 2
3
49 50