change a property of an object array without looping

Asked

Viewed 417 times

0

Good morning, I have an array of objects with several properties and one of them is the data property that I would like to convert. But I wonder if there’s any way to do it without using a loop.

var arr = [{data: 2018/01/02, nome: 'Teste}, 
           {data: 2018/03/03, nome: ' Outro Teste},
           {data: 2019/02/29, nome: 'João'} ... ]

I need a new array, where the date property is in DD-MM-AA format and keeps the other properties unchanged. If anyone knows how to do it without needing to do one is grateful

  • 1

    It is possible, but then you would have to write a line changing the value for each of the index of the array. I don’t understand why not use a loop/loop

  • in fact it is a very extensive array, I imagined that there would be some faster way, without having to go through a loop

  • 1

    The loop was made exactly to make extensive actions quickly. To replace this as you want just need 2 lines of code well say

  • 1

    @Elisangelacarladesouza whatever syntax you choose, whether or not it’s a loop, you’ll always have to access each obj and convert the date... It’s a loop, here you have several: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.