how to sort out problem of undefined index in javascript code example
Example: php undefined index
// Your array index has no value or is not referencing anything,
// The easiest way to overcome this is to simply check whether
// it has been defined
if (isset($arr[$i])) {
// Do something
}