-3
Hello. Today I have a question. How can I efficiently create a function that allows me to clean a specific object? For example:
const obj = {
chave1: 'conteudo',
chave2: {},
chave3: '',
chave4: {
chave1: 'conteudo1',
chave2: {}
chave3: {
chave1: [],
chave2: {},
chave3 'conteudo2'
}
}
}
As output would have to come out the following:
{
chave1: 'conteudo',
chave4: {
chave1: 'conteudo1',
chave3: {
chave3: 'conteudo2',
}
}
}
How can I solve the problem without compromising performance?
It depends on the version you are using.. es2015 ? es2016 ? native ?
– 13dev
"How can I solve the problem without compromising performance?" I don’t care about summers but about performance. What is the best way to iterate objects? Regardless of versions.
– Cláudio Hilário
"Without compromising performance" - this will depend on the object. You have to iterate over the whole object to remove the empty values, there is no other way. It costs processing time. If the object is small, it should not have much impact on performance. If it is large, it may have more impact.
– bfavaretto