subha rr Posted May 23, 2009 Report Share Posted May 23, 2009 Hi.....To find whether given value is present in an array or not. Enter the value into textbox and find whether the given value is found in array or not....How to write code in javascriptPls help meRegardsSubha Link to comment Share on other sites More sharing options...
Shade Posted May 23, 2009 Report Share Posted May 23, 2009 (edited) var data = new Array(value1, value2, ...... );var value = "myvalue";var num = 0;for(var i = 0; i < data.length; i ++){ if ( data[i] == value ) { num++; }}if ( num > 0 ) { alert("the value " + value + " has occurred " + num + " times"); } else { alert("the value " + value + " was not found"); } Edited May 23, 2009 by Shade Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now