JSFiddle - React, Tailwind, and code Playground

by bruno

HTML

<div class="ui-widget">
    <label for="tags">Tags: </label>
    <input id="tags" />
</div>

JavaScript

var o = {
  anotherProp: "hello",
  person : [
    { 
      name : 'paul',
      title : 'prof',
      profession : 'teacher',
      start: '2010-10-10'
    },
    { 
      name : 'joe',
      title : 'dr',
      profession : 'scientist',
      start: '2000-01-01'
    }
  ],
  book : [
    {
       title : 'the cat in the hat'
    }
  ] 
};


var retrieveUniqueProps = ( function ( ) {

    var result = [];
    var added = {};

    isArray = function( o ) { 
        return Object.prototype.toString.call( o ) === "[object Array]";
    };

    isObject = function( o ) { return typeof o === "object"; };

    return function ( obj, parentPath ) {

        if( isArray( obj ) ) {

            for( var i = 0; i < obj.length; i++ ) {

                if( isArray( obj[i] ) || isObject( obj[i] ) ){ 
                    retrieveUniqueProps( obj[i], parentPath ); 
                }
            }

        } else if ( isObject( obj ) ) {

            for( var a in obj ) {

                if( obj.hasOwnProperty( a ) ) {

                    var fullpath = parentPath ? parentPath + "." + a : a;
                    if( !added[ fullpath ] ) {
                        result.push( fullpath );
                        added[ fullpath ] = true;
                    }

                    if( isArray( obj[a] ) || isObject( obj[a] ) ){ 
                        retrieveUniqueProps( obj[a], parentPath ? parentPath + "." + a : a ); 
                    }
                }
            }
        }

        return result;
    };


}());

var uniquePropertyNames = retrieveUniqueProps( o, "" );


console.log( uniquePropertyNames );

$(document).ready( function( ) {
    $("#tags").autocomplete({
        source: function(request, response) {
                    // The term the user searched for;
                    var term = request.term;

                    // Extract matching items:
                    var matches = $.grep(uniquePropertyNames, function(item, index) {
                        //...