Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
Matriz anidada y filtro de Javascript

Aquí está mi código

https://codepen.io/hobbesa/pen/jOGREKy?editors=1111

Estoy tratando de obtener el precio de solo los días de semana. ¿Cómo hago eso?

 this.getPriceWeekDay = this.StrategypricingDetail.map((rec) => rec.map((daysOfWeek) => { return daysOfWeek; }),

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Primero, puede filtrar elementos que no contengan Saturday o Sunday mediante el uso de métodos de filtro y búsqueda , y luego iterar sobre la lista filtrada por método de mapa para extraer solo la propiedad de precio, como esta:

 let StrategypricingDetail = [ { id: 3, name: "test", price: 30, daysOfWeek: [ { id: 1, name: "Monday" }, { id: 2, name: "Tuesday" }, { id: 3, name: "Wednesday" } ] }, { id: 23, name: "Testing2", price: 10, daysOfWeek: [ { id: 1, name: "Monday" }, { id: 2, name: "Tuesday" } ] }, { id: 13, name: "Testing3", price: 14, daysOfWeek: [ { id: 1, name: "Saturaday" }, { id: 2, name: "Sunday" } ] } ]; const weekDaysPrice = StrategypricingDetail.filter(({daysOfWeek}) => !daysOfWeek.find(({name}) => name == 'Saturaday' || name == 'Sunday')).map(({price}) => price); console.log(weekDaysPrice);

about 4 years ago · Juan Pablo Isaza Relatório

0

Una solución que podría usar a continuación.

 let strategypricingDetail = [ { id: 3, name: "test", price: 30, daysOfWeek: [ { id: 1, name: "Monday" }, { id: 2, name: "Tuesday" }, { id: 3, name: "Wednesday" } ] }, { id: 23, name: "Testing2", price: 10, daysOfWeek: [ { id: 1, name: "Monday" }, { id: 2, name: "Tuesday" } ] }, { id: 13, name: "Testing3", price: 14, daysOfWeek: [ { id: 1, name: "Saturaday" }, { id: 2, name: "Sunday" } ] } ]; let finalList = []; // Create list of eligible days for the search let daysToInclude = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ]; strategypricingDetail.forEach((item, index) => { for (let i = 0; i < item.daysOfWeek.length; i++) { // Check if the day is in the eligible list if (daysToInclude.includes(item.daysOfWeek[i].name)) { finalList.push(item); break; // When found, break out of the search after adding it to the final list. } } }); console.log(finalList)

En esta solución, recorre los elementos disponibles y luego compara la lista 'daysOfWeel' de cada elemento con una lista de días elegibles. Tan pronto como encuentre uno, dejará de buscar y agregará ese elemento a una nueva lista, hasta que termine con la lista de días apropiados.

about 4 years ago · Juan Pablo Isaza Relatório

0

 //StrategypricingDetail is the whole json const StrategypricingDetail = [ { id: 3, name: "test", price: 30, daysOfWeek: [ { id: 1, name: "Monday" }, { id: 2, name: "Tuesday" }, { id: 3, name: "Wednesday" } ] }, { id: 23, name: "Testing2", price: 10, daysOfWeek: [ { id: 1, name: "Monday" }, { id: 2, name: "Tuesday" } ] }, { id: 13, name: "Testing3", price: 14, daysOfWeek: [ { id: 1, name: "Saturaday" }, { id: 2, name: "Sunday" } ] } ]; const weekends = ["Saturaday","Sunday"] // Approach // we have to filter some element based on condition // condition will be days should not belong to weekends this.getPriceWeekDay = StrategypricingDetail.filter((rec) => { for(let dayIndex = 0 ; dayIndex < rec.daysOfWeek.length; dayIndex++){ const dayName = rec.daysOfWeek[dayIndex].name; if(weekends.includes(dayName)){ return; } } return rec; }).map(({price}) => price); console.log(getPriceWeekDay);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda