Within my dashboard, the user makes a filter that goes to the database and returns a JavaScript object through an asynchronous request and the array extension can vary, being able to have a length
from 1 to 3, always !
So sometimes when the user does the filter, on my console it returns the following:
Andwhenyouclickonthelog,inthisexample,thekey2ofthearrayismarked,indicatingthatitisundefined.Icheckedthedatabaseandeverythingandthat'sit.
SoforthisIlookedintheforumonthesubjectandIbuiltthisfunctionthatisbeingusedasintheimageabove:
functiontratarValorIndefinido(vl){if(typeof(vl)==="undefined"){
vl ="S/ HISTÓRICO";
}
};
But instead of stamping "S / HISTORY", it is returning undefined
.
Where am I going wrong?
*** HOW DO I CURRENT OBJECT?
var dataBar = {
labels: [dataChart[0]['mesReferencia'],dataChart[1]['mesReferencia'],dataChart[2]['mesReferencia']],
datasets: [{
label: "CPF's Enviados",
backgroundColor: "rgba(0,51,90,0.8)",
borderColor: "rgba(0,51,90,0.9)",
borderWidth: 2,
hoverBackgroundColor: "rgba(0,51,90,0.9)",
hoverBorderColor: "rgba(0,51,90,1)",
data: [dataChart[0]['cpfsEnviados'],dataChart[1]['cpfsEnviados'],dataChart[2]['cpfsEnviados']]
},
** structure of data[0]
: