Reputation: 1259
I am storing some data in array. which is gonna be like this
datas[
password:"dfsdfsd",
username : "dfgdgdfg55555",
password:"deep",
username : "dfgdgdfg56556",
password:"hello",
username : "dfgdgdfg65",
password:"hello1234",
username : "dfgdgdfg123"
]
now i want to camapare the username. and i am trying like it and want if the condition is true(take me to another page) but don't know how to do that.
checkCred(){
var details_array = this.state.datas1 ;
console.log(details_array);
for(var i=0; i < details_array.length; i++) {
var currentObject = details_array[i];
if (this.email.value === currentObject.username) {
console.log('yes done it');
window.location = '/Index';// this is not working and think window.location is stupid methed...
// please guide me if you have any better idea than this
}
}
}
<input ref={(e) => this.email = e} name="email" type="email" /><br/>
Am I doing correct way or not?
Upvotes: 2
Views: 80
Reputation: 556
Make following changes to work as per expectations,
var details_array = this.state.datas ;
for(var i=0; i < details_array.length; i++){
var currentObject = details_array[i];
if (this.email.value === currentObject.username){
console.log('yes done');
}
}
Note: hope you have data in details_array.
Upvotes: 2