I have the following code

if (list.Date[0] != 'undefined') {
            for (var i in list) {
                var date = list[i].Data;
                var year = date.substr(0, 4);
                var month = date.substr(5, 2);
                var day = date.substr(8, 2);

                var newDate = day + "/" + month + "/" + year + " " + date.substr(11, 8);

                list[i].Date = newDate;
            }
        }

It's inside a validation code, that makes the validation of all the forms. Some has the field date and others don't. How can I do a validation if inside the array has the date field?

for (var i in list) {
    if('Data' in list[i])
    {
        var data = list[i].Data;
        var ano = data.substr(0, 4);
        var mes = data.substr(5, 2);
        var dia = data.substr(8, 2);

        var dataBr = dia + "/" + mes + "/" + ano + " " + data.substr(11, 8);

        list[i].Data = dataBr;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.