Loading ...

JavaScript: Convert all the items in object to lowercase

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » JavaScript: Convert all the items in object to lowercase

JavaScript: Convert all the items in object to lowercase

Posts under the topic: JavaScript: Convert all the items in object to lowercase

Posted: 10/10/2011

Lurker 100  points  Lurker
  • Joined on: 9/11/2010
  • Posts: 20

Hi,
I have an object in JavaScript whose values may be in UpperCase. I have a requirement where I need to convert all the values of the objects to lower case. Below is my code:

    <script type="text/javascript">
        var obj = { a: 'Hello', b: 'How', c: 'Are', d: 'You' };
        //obj.toLowerCase() ?    
    </script>

The output I need is:

var obj = { a: 'hello', b: 'how', c: 'are', d: 'you' };



 


Posted: 10/11/2011

Guru 16773  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

    <script type="text/javascript">
        var obj = { a: 'Hello', b: 'How', c: 'Are', d: 'You' };
        for(var x in obj) {
            obj[x] = obj[x].toLowerCase();
        }
    </script>


Page 1 of 1 (2 items)