본문 바로가기

Spring

JSON 키,값 FOR문으로 쉽게 빼내기

<script>

    var userinfo = [{"mail_id":"jjj@naver.com","pw":"@!$!zz","use_yn":"y","phone_num":"01066225451","type":"user","addr":"서울시강서구둔촌동","sn7":"9503111"},{"mail_id":"mjkim@steveleejava.com","pw":"qwerasdf","use_yn":"y","phone_num":"01066662233","type":"admin","addr":"서울시서초구서초동","sn7":"8503162"},{"mail_id":"stevelee@steveleejava.com","pw":"1234zz","use_yn":"y","phone_num":"01077778888","type":"admin","addr":"서울시강남구논현동","sn7":"9209301"}];


    function maketable(){

        //@hint

        //Object.keys(userinfo).length

        //var [key, value] of Object.entries(userinfo)

        //var tabletag = document.createElement('table');

      
		//userinfo.mail_id 는 값이 나올것이다.
		//변수안의 객체변수도 이름을 가지고있는데, 이를 하드코딩할 필요는 없다.
        
        for(int i=0;i<Object.keys(userinfo).length; i++){
        	  for(var [key,value] of Object.entries(userInfo)){
            	  console.log(key+':'+value);
         	  }
        }
</script>