7

it's me again, now with .

I have a , inside it have two "rows", they are Description and ubication. I need to filter the array by Description.

How can I filter this? The description it's in text format for example "Impact" or "Wiu wiu".

I know the function filter() of have a numeric condition but no have a text condition or I haven't seen it been use for that.

Thank you so much for your help.

0

1 Answer 1

7

No still you can do with Text as well,

let filtered = yourArray.filter(t=>t.Description ==='impact');

DEMO

let mydata = {
  "ArrayBotones": [
    {
      "descripcion": "Impacto",
      "ubicacion": "sonidos/impacto.mp3"
    },
    {
      "descripcion": "Soy Fede",
      "ubicacion": "sonidos/holasoyfede.wav"
    },
    {
      "descripcion": "Wiu wiu",
      "ubicacion": "sonidos/wiuwiu.wav"
    },
    {
      "descripcion": "3 carajos",
      "ubicacion": "sonidos/3carajos.wav"
    },
    {
      "descripcion": "Apurate Jose",
      "ubicacion": "sonidos/apuratejose.wav"
    },
    {
      "descripcion": "No, no se",
      "ubicacion": "sonidos/nonose.wav"
    }
  ]
};

let result = mydata.ArrayBotones.filter(t=>t.descripcion === 'Impacto');
console.log(result);

Sign up to request clarification or add additional context in comments.

7 Comments

Not works :/ let Botones = ArrayBotones; console.log(Botones); let Botones2 = Botones.filter(botones=>Botones.descripcion ==='impact'); console.log(Botones2); }
can you post your Botons array
The array come empty :C
dude ! if the array is empty how can you filter?
{ "ArrayBotones":[ { "descripcion": "Impacto", "ubicacion" : "sonidos/impacto.mp3"}, { "descripcion": "Soy Fede", "ubicacion" : "sonidos/holasoyfede.wav" }, { "descripcion": "Wiu wiu", "ubicacion" : "sonidos/wiuwiu.wav" }, { "descripcion": "3 carajos", "ubicacion" : "sonidos/3carajos.wav" }, { "descripcion": "Apurate Jose", "ubicacion" : "sonidos/apuratejose.wav" }, { "descripcion": "No, no se", "ubicacion" : "sonidos/nonose.wav" } ] }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.