Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrog?

Status
Not open for further replies.

dumistefanlex

Programmer
Jan 18, 2008
4
RO
What is wrong with thids code?
function emptyArray(array){
for( i=0; i<array.length; i++){
delete array;
}
return array;
}
Colud you help me
Thank you
 
There is nothing wrong with that code. However there may well be something wrong with what you expect it to do.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
delete is not a function call.

Code:
function emptyArray(array) {
    array.length = 0;

    return array;
}

This is untested, but should work.
 
Ah, I stand corrected. Heck, even when answering you learn something, haha.
 
Thanks a lot.
The code is supose to empty an array.
Could you helpm me wit also
function isLoggedIn(){
return
document.cookie.indexOf( 'userIsLoggedIn=true' );
}
??? is there anything wrong?
 
Thanks a lot
any help with what is missing here?
var mytest1 = new Test();
mytest1.setNumber( 2 )

var mytest2 = new Test();
mytest2.setNumber( 3 );

if( mytest1 + mytest2 == 5 ) alert('Works!')

 
why not just
Code:
array.length = 0;
or you could delete the array entirely and declare a new one, or
Code:
array = [];
. I like the last one best. oh and don't name arrays "array", Avoid naming things after a keyword. and where is the setNumber function?
 
You want to remove all elements in an array??
Just define a new one..

Code:
var an_array_with_items = ['a','b','c']; // An array
an_array_with_items = []; // Empty array

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
hmmmm... my homework sense is tingling.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
I agree. dumistefanlex you do know it is against Forum policy to submit homework questions, right? Please read the section below the submit button...


Promoting, selling, recruiting and student posting
are not allowed in the forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top