Why i can access the property inside dataValues without accessing dataValues property?
Example:
const data = await Product.findAll({
attributes: ['id', 'name', 'price', 'stock', 'sku']
});
console.log(data);
Result of console.log(data):
[
Product {
dataValues: {
id: 1,
name: 'Samsung Galaxy A53',
price: 5000000,
stock: 100,
sku: 'SM001'
},
_previousDataValues: {
id: 1,
name: 'Samsung Galaxy A53',
price: 5000000,
stock: 100,
sku: 'SM001'
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
Product {
dataValues: {
id: 2,
name: 'Samsung Galaxy S22',
price: 10000000,
stock: 100,
sku: 'SM002'
},
_previousDataValues: {
id: 2,
name: 'Samsung Galaxy S22',
price: 10000000,
stock: 100,
sku: 'SM002'
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
}
]
I think if i want to get 'Samsung Galaxy A53', i must write a code like this:
console.log(data[0].dataValues.name) // it is works
But why i can get 'Samsung Galaxy A53' with a code like this?
console.log(data[0].name) // i can access directly to name property without using dataValues property