2 Replies - 377 Views - Last Post: 09 June 2012 - 03:38 AM

#1 nym-ph  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 27
  • Joined: 18-December 10

splice() not returning the removed element in the array

Posted 08 June 2012 - 06:15 PM

Hi everyone!

I'm trying to remove an object, from an Array.

	for(var i in books){
		if(books[i].isbn==isbn) {	
                         cart.push(books.splice(i, 1));
                }
        }


For some reason, nothing is going into my cart Array! I know it's being successfully removed from books, because i tried dumping it. And it's not there anymore.

Documentation says splice() should return the element!

Anyone has any idea what I might be missing?

Thank you!

This post has been edited by nym-ph: 08 June 2012 - 06:17 PM


Is This A Good Question/Topic? 0
  • +

Replies To: splice() not returning the removed element in the array

#2 nym-ph  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 27
  • Joined: 18-December 10

Re: splice() not returning the removed element in the array

Posted 08 June 2012 - 06:22 PM

This code, was actually working... It just happens that it's returning an Array! And show be treated has such after that.

I was not accessing the returned element the right way.

This did trick,

var returnedElement = books.splice(i, 1);
      alert(returnedElement[0].isbn)


This post has been edited by nym-ph: 08 June 2012 - 06:23 PM

Was This Post Helpful? 2
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6053
  • View blog
  • Posts: 23,488
  • Joined: 23-August 08

Re: splice() not returning the removed element in the array

Posted 09 June 2012 - 03:38 AM

Good job debugging, and thank you for coming back and telling us the solution!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1